@@ -82,13 +82,8 @@ def __init__(
8282 )
8383 except PyMathicsLoadException as e :
8484 raise
85- # print(e.module + " is not a valid pymathics module.")
86- #continue
8785 except ImportError as e :
8886 raise
89- #print(e.__repr__())
90- #continue
91- # print(module + loaded_module.pymathics_version_data['version'] + " by " + loaded_module.pymathics_version_data['author'])
9287
9388 if builtin_filename is not None :
9489 builtin_file = open (builtin_filename , "wb" )
@@ -120,7 +115,7 @@ def load_pymathics_module(self, module, remove_on_quit=True):
120115 from an external Python module in the pymathics module namespace.
121116 """
122117 import importlib
123- from mathics .builtin import is_builtin , builtins , builtins_by_module , Builtin
118+ from mathics .builtin import is_builtin , builtins_by_module , Builtin
124119 # Ensures that the pymathics module be reloaded
125120 import sys
126121 if module in sys .modules :
@@ -173,17 +168,13 @@ def load_pymathics_module(self, module, remove_on_quit=True):
173168 def clear_pymathics_modules (self ):
174169 from mathics .builtin import builtins , builtins_by_module
175170
176- # Remove all modules that are not in mathics
177- # print("cleaning pymathics modules")
178171 for key in list (builtins_by_module .keys ()):
179172 if not key .startswith ("mathics." ):
180- print (f'removing module "{ key } " not in mathics.' )
181173 del builtins_by_module [key ]
182174 for key in pymathics :
183175 del self .pymathics [key ]
184176
185177 self .pymathics = {}
186- # print("everything is clean")
187178 return None
188179
189180 def clear_cache (self , name = None ):
@@ -422,10 +413,14 @@ def get_definition(self, name, only_if_exists=False) -> "Definition":
422413 builtin = self .builtin .get (name , None )
423414
424415 candidates = [user ] if user else []
416+ builtin_instance = None
425417 if pymathics :
418+ builtin_instance = pymathics
426419 candidates .append (pymathics )
427420 if builtin :
428421 candidates .append (builtin )
422+ if builtin_instance is None :
423+ builtin_instance = builtin
429424
430425 definition = candidates [0 ] if len (candidates )== 1 else None
431426 if len (candidates )> 0 and not definition :
@@ -462,6 +457,7 @@ def get_definition(self, name, only_if_exists=False) -> "Definition":
462457 options = options ,
463458 nvalues = sum ((c .nvalues for c in candidates ),[]),
464459 defaultvalues = sum ((c .defaultvalues for c in candidates ),[]),
460+ builtin = builtin_instance
465461 )
466462
467463 if definition is not None :
0 commit comments