File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change 1212import random
1313import re
1414import string
15+ import warnings
1516from contextlib import contextmanager
1617from typing import Dict , FrozenSet , List , Union
1718
@@ -805,15 +806,23 @@ def perform_math_eval(self, in_str):
805806 unmodified (if unsuccessful)
806807
807808 """
808- try :
809- math_ast = ast .parse (in_str , mode = "eval" )
810- out_str = self .eval_math (math_ast .body )
811- return out_str
812- except MathEvaluationError as e :
813- logger .debug (f' Math input is: "{ in_str } "' )
814- logger .debug (e )
815- except RambleSyntaxError as e :
816- raise RambleSyntaxError (f'{ str (e )} in "{ in_str } "' )
809+ with warnings .catch_warnings (record = True ) as wal :
810+ try :
811+ math_ast = ast .parse (in_str , mode = "eval" )
812+ out_str = self .eval_math (math_ast .body )
813+ return out_str
814+ except MathEvaluationError as e :
815+ logger .debug (f' Math input is: "{ in_str } "' )
816+ logger .debug (e )
817+ except RambleSyntaxError as e :
818+ raise RambleSyntaxError (f'{ str (e )} in "{ in_str } "' )
819+ except Exception as e :
820+ logger .debug (f"ast.parse hit the following exception on input: { in_str } " )
821+ logger .debug (f"{ e } " )
822+
823+ for warn in wal :
824+ if r"invalid escape sequence '\{'" not in str (warn .message ):
825+ logger .warn (str (warn .message ))
817826
818827 return in_str
819828
You can’t perform that action at this time.
0 commit comments