Skip to content

Commit 1d9794e

Browse files
committed
sage.misc.dev_tools.find_objects_from_name: use a copy of sys.modules
In an attempt to avoid the following error on the CI... dt.find_objects_from_name('FareySymbol') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/misc/dev_tools.py", line 279, in find_objects_from_name for smodule_name, smodule in sys.modules.items(): RuntimeError: dictionary changed size during iteration we make a copy of the sys.modules dict before iterating over its items.
1 parent 4b603c1 commit 1d9794e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/sage/misc/dev_tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,12 @@ def find_objects_from_name(name, module_name=None, include_lazy_imports=False):
275275
"""
276276
from sage.misc.lazy_import import LazyImport
277277

278+
# Create a copy to avoid errors if the sys.modules dict changes
279+
# while we are iterating over it.
280+
mods = sys.modules.copy()
281+
278282
obj = []
279-
for smodule_name, smodule in sys.modules.items():
283+
for smodule_name, smodule in mods.items():
280284
if module_name and not smodule_name.startswith(module_name):
281285
continue
282286
if hasattr(smodule, '__dict__') and name in smodule.__dict__:

0 commit comments

Comments
 (0)