1- #!/usr/bin/env python3
21# -*- coding: utf-8 -*-
32
43import re
109import typing
1110from typing import Any , cast
1211
12+ from mathics .version import __version__ # noqa used in loading to check consistency.
13+
1314from mathics .core .definitions import Definition
1415from mathics .core .parser .util import SystemDefinitions , PyMathicsDefinitions
1516from mathics .core .rules import Rule , BuiltinRule , Pattern
2627)
2728from mathics .core .numbers import get_precision , PrecisionValueError
2829
30+
2931def get_option (options , name , evaluation , pop = False , evaluate = True ):
3032 # we do not care whether an option X is given as System`X,
3133 # Global`X, or with any prefix from $ContextPath for that
@@ -82,6 +84,7 @@ def __init__(self, *args, **kwargs):
8284
8385 def contribute (self , definitions , is_pymodule = False ):
8486 from mathics .core .parser import parse_builtin_rule
87+
8588 # Set the default context
8689 if not self .context :
8790 self .context = "Pymathics`" if is_pymodule else "System`"
@@ -102,7 +105,8 @@ def contribute(self, definitions, is_pymodule=False):
102105 # used, so it won't work.
103106 if option not in definitions .builtin :
104107 definitions .builtin [option ] = Definition (
105- name = name , attributes = set ())
108+ name = name , attributes = set ()
109+ )
106110
107111 # Check if the given options are actually supported by the Builtin.
108112 # If not, we might issue an optx error and abort. Using '$OptionSyntax'
@@ -144,9 +148,7 @@ def check_options(options_to_check, evaluation):
144148
145149 for pattern , function in self .get_functions (is_pymodule = is_pymodule ):
146150 rules .append (
147- BuiltinRule (
148- name , pattern , function , check_options , system = True
149- )
151+ BuiltinRule (name , pattern , function , check_options , system = True )
150152 )
151153 for pattern , replace in self .rules .items ():
152154 if not isinstance (pattern , BaseExpression ):
@@ -246,7 +248,8 @@ def contextify_form_name(f):
246248 # used, so it won't work.
247249 if option not in definitions .builtin :
248250 definitions .builtin [option ] = Definition (
249- name = name , attributes = set ())
251+ name = name , attributes = set ()
252+ )
250253 defaults = []
251254 for spec , value in self .defaults .items ():
252255 value = parse_builtin_rule (value )
@@ -266,7 +269,7 @@ def contextify_form_name(f):
266269 attributes = attributes ,
267270 options = options ,
268271 defaultvalues = defaults ,
269- builtin = self
272+ builtin = self ,
270273 )
271274 if is_pymodule :
272275 definitions .pymathics [name ] = definition
@@ -537,7 +540,7 @@ def get_constant(self, precision, evaluation, have_mpmath=False):
537540
538541 sympy_fn = self .to_sympy ()
539542 if d is None :
540- result = self .get_mpmath_function ()if have_mpmath else sympy_fn ()
543+ result = self .get_mpmath_function () if have_mpmath else sympy_fn ()
541544 return MachineReal (result )
542545 else :
543546 return PrecisionReal (sympy_fn .n (d ))
@@ -630,15 +633,15 @@ def head(self):
630633
631634 @head .setter
632635 def head (self , value ):
633- raise ValueError (' BoxConstruct.head is write protected.' )
636+ raise ValueError (" BoxConstruct.head is write protected." )
634637
635638 @property
636639 def leaves (self ):
637640 return self ._leaves
638641
639642 @leaves .setter
640643 def leaves (self , value ):
641- raise ValueError (' BoxConstruct.leaves is write protected.' )
644+ raise ValueError (" BoxConstruct.leaves is write protected." )
642645
643646 # I need to repeat this, because this is not
644647 # an expression...
@@ -663,14 +666,17 @@ def has_form(self, heads, *leaf_counts):
663666 if leaf_counts and leaf_counts [0 ] is not None :
664667 count = len (self ._leaves )
665668 if count not in leaf_counts :
666- if (len (leaf_counts ) == 2 and # noqa
667- leaf_counts [1 ] is None and count >= leaf_counts [0 ]):
669+ if (
670+ len (leaf_counts ) == 2
671+ and leaf_counts [1 ] is None # noqa
672+ and count >= leaf_counts [0 ]
673+ ):
668674 return True
669675 else :
670676 return False
671677 return True
672678
673- def flatten_pattern_sequence (self , evaluation ) -> ' BoxConstruct' :
679+ def flatten_pattern_sequence (self , evaluation ) -> " BoxConstruct" :
674680 return self
675681
676682 def get_option_values (self , leaves , ** options ):
@@ -681,6 +687,7 @@ def get_option_values(self, leaves, **options):
681687 default .update (options )
682688 else :
683689 from mathics .core .parser import parse_builtin_rule
690+
684691 default = {}
685692 for option , value in self .options .items ():
686693 option = ensure_context (option )
0 commit comments