1717from mathics .core .convert import sympy_symbol_prefix , SympyExpression
1818import base64
1919
20- from mathics_scanner .characters import replace_wl_with_plain_text
2120
2221def fully_qualified_symbol_name (name ) -> bool :
2322 return (
@@ -127,7 +126,12 @@ def from_python(arg):
127126 # return Symbol(arg)
128127 elif isinstance (arg , dict ):
129128 entries = [
130- Expression ("Rule" , from_python (key ), from_python (arg [key ]),) for key in arg
129+ Expression (
130+ "Rule" ,
131+ from_python (key ),
132+ from_python (arg [key ]),
133+ )
134+ for key in arg
131135 ]
132136 return Expression (SymbolList , * entries )
133137 elif isinstance (arg , BaseExpression ):
@@ -486,7 +490,9 @@ def format_expr(expr):
486490 finally :
487491 evaluation .dec_recursion_depth ()
488492
489- def format (self , evaluation , form , ** kwargs ) -> typing .Union ["Expression" , "Symbol" ]:
493+ def format (
494+ self , evaluation , form , ** kwargs
495+ ) -> typing .Union ["Expression" , "Symbol" ]:
490496 """
491497 Applies formats associated to the expression, and then calls Makeboxes
492498 """
@@ -508,7 +514,7 @@ def get_precision(self):
508514 def get_option_values (self , evaluation , allow_symbols = False , stop_on_error = True ):
509515 options = self
510516 if options .has_form ("List" , None ):
511- options = options .flatten (Symbol ( "List" ) )
517+ options = options .flatten (SymbolList )
512518 values = options .leaves
513519 else :
514520 values = [options ]
@@ -1623,9 +1629,9 @@ def filter_leaves(self, head_name):
16231629
16241630 def apply_rules (self , rules , evaluation , level = 0 , options = None ):
16251631 """for rule in rules:
1626- result = rule.apply(self, evaluation, fully=False)
1627- if result is not None:
1628- return result"""
1632+ result = rule.apply(self, evaluation, fully=False)
1633+ if result is not None:
1634+ return result"""
16291635
16301636 # to be able to access it inside inner function
16311637 new_applied = [False ]
@@ -1775,17 +1781,21 @@ def thread(self, evaluation, head=None) -> typing.Tuple[bool, "Expression"]:
17751781 return True , Expression (head , * leaves )
17761782
17771783 def is_numeric (self ) -> bool :
1778- return self ._head .get_name () in system_symbols (
1779- "Sqrt" ,
1780- "Times" ,
1781- "Plus" ,
1782- "Subtract" ,
1783- "Minus" ,
1784- "Power" ,
1785- "Abs" ,
1786- "Divide" ,
1787- "Sin" ,
1788- ) and all (leaf .is_numeric () for leaf in self ._leaves )
1784+ return (
1785+ self ._head .get_name ()
1786+ in system_symbols (
1787+ "Sqrt" ,
1788+ "Times" ,
1789+ "Plus" ,
1790+ "Subtract" ,
1791+ "Minus" ,
1792+ "Power" ,
1793+ "Abs" ,
1794+ "Divide" ,
1795+ "Sin" ,
1796+ )
1797+ and all (leaf .is_numeric () for leaf in self ._leaves )
1798+ )
17891799 # TODO: complete list of numeric functions, or access NumericFunction
17901800 # attribute
17911801
@@ -1905,9 +1915,7 @@ def do_copy(self) -> "Symbol":
19051915 return Symbol (self .name )
19061916
19071917 def boxes_to_text (self , ** options ) -> str :
1908- if options .get ("encoding" , "UTF-8" ) in ("UTF-8" , "Unicode" ):
1909- return str (self .name )
1910- return replace_wl_with_plain_text (str (self .name ), False )
1918+ return str (self .name )
19111919
19121920 def atom_to_boxes (self , f , evaluation ) -> "String" :
19131921 return String (evaluation .definitions .shorten_name (self .name ))
@@ -2057,7 +2065,7 @@ def is_numeric(self) -> bool:
20572065def _ExponentFunction (value ):
20582066 n = value .get_int_value ()
20592067 if - 5 <= n <= 5 :
2060- return Symbol ( "Null" )
2068+ return SymbolNull
20612069 else :
20622070 return value
20632071
@@ -2726,9 +2734,7 @@ def boxes_to_text(self, show_string_characters=False, **options) -> str:
27262734 ):
27272735 value = value [1 :- 1 ]
27282736
2729- if options .get ("encoding" , "UTF-8" ) in ("UTF-8" , "Unicode" ):
2730- return value
2731- return replace_wl_with_plain_text (value , False )
2737+ return value
27322738
27332739 def boxes_to_xml (self , show_string_characters = False , ** options ) -> str :
27342740 from mathics .core .parser import is_symbol_name
0 commit comments