Fix #121021: Avoid size change of addon_modules during iteration

Copy modules before filtering `addon_modules` to avoid
change of dictionnary size during iterations. Otherwise errors
can be triggerd when running `python -m pytest test.py` since
it may modify the module dict.

Co-authored-by: Alexis-19 <alexis-19@noreply.localhost>
Pull Request: https://projects.blender.org/blender/blender/pulls/121100
This commit is contained in:
YimingWu
2024-05-11 08:58:20 +02:00
committed by YimingWu
parent 1953f3cd51
commit c324c19765

View File

@@ -584,8 +584,9 @@ def disable_all():
#
# Either way, running 3rd party logic here can cause undefined behavior.
# Use direct `__dict__` access to bypass `__getattr__`, see: #111649.
modules = sys.modules.copy()
addon_modules = [
item for item in sys.modules.items()
item for item in modules.items()
if type(mod_dict := getattr(item[1], "__dict__", None)) is dict
if mod_dict.get("__addon_enabled__")
]