refactor(worker): iterate a sys.modules copy instead of list() (Sonar S7504) (SIENTIAPDE-2214)

This commit is contained in:
PedroHMCosme
2026-10-22 12:37:11 -03:00
parent dfbdd4b605
commit 29700169ad

View File

@@ -79,8 +79,8 @@ def _get_runtime(runtime: str | None) -> str:
def _loaded_distribution_versions() -> dict[str, str]:
"""Version on disk of every installed distribution whose top-level module is imported."""
# list() copies the keys: another thread importing while we iterate would raise RuntimeError.
loaded = {name.partition('.')[0] for name in list(sys.modules)}
# Iterate a copy: another thread importing while we iterate would raise RuntimeError.
loaded = {name.partition('.')[0] for name in sys.modules.copy()}
return {
dist: importlib.metadata.version(dist)
for module, dists in importlib.metadata.packages_distributions().items()