Skip to content

Commit cf325c5

Browse files
committed
fixing the loading mechanism in pymathics
1 parent 6c4e2a0 commit cf325c5

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

mathics/core/definitions.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,14 @@ def load_pymathics_module(self, module, remove_on_quit=True):
152152
if not var.context:
153153
var.context = "Pymathics`"
154154
symbol_name = instance.get_name()
155-
builtins[symbol_name] = instance
155+
self.pymathics[symbol_name] = instance
156156
builtins_by_module[loaded_module.__name__].append(instance)
157157
newsymbols[symbol_name] = instance
158158

159159
for name in newsymbols:
160160
luname = self.lookup_name(name)
161161
self.user.pop(name, None)
162-
if remove_on_quit and name not in self.pymathics:
163-
self.pymathics[name] = self.builtin.get(name, None)
164-
self.builtin.update(newsymbols)
165-
162+
166163
for name, item in newsymbols.items():
167164
if name != "System`MakeBoxes":
168165
item.contribute(self, is_pymodule=True)
@@ -177,25 +174,9 @@ def clear_pymathics_modules(self):
177174
if not key.startswith("mathics."):
178175
print(f'removing module "{key}" not in mathics.')
179176
del builtins_by_module[key]
180-
# print("reloading symbols from current builtins.")
181-
for s in self.pymathics:
182-
if s in self.builtin:
183-
# If there was a true built-in definition for the symbol, restore it, else, remove he symbol.
184-
if self.pymathics[s]:
185-
self.builtin[s] = self.pymathics[s]
186-
builtins[s] = None
187-
for key, val in builtins_by_module.items():
188-
for simb in val:
189-
if simb.get_name() == s:
190-
builtins[s] = simb
191-
break
192-
if builtins[s] is not None:
193-
break
194-
if builtins[s] is None:
195-
builtins.__delitem__(s)
196-
else:
197-
self.builtin.__delitem__(s)
198-
builtins.__delitem__(s)
177+
for key in pymathics:
178+
del self.pymathics[key]
179+
199180
self.pymathics = {}
200181
# print("everything is clean")
201182
return None

0 commit comments

Comments
 (0)