SAM0123-320: refactor: snapshot sys.modules with copy() before eviction scan

Sonar flagged `list(sys.modules.items())` as an unnecessary `list()`. The
snapshot is required (a concurrent import or a lazy `__getattr__` can mutate
`sys.modules` mid-scan), so make it explicit with `copy()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 08:22:44 -03:00
parent d91a0d069c
commit 9e27688a70

View File

@@ -535,9 +535,10 @@ class MLFlowRepository(SientiaMonitoring):
artifact_prefixes = tuple(path.join(directory, '') for directory in ARTIFACT_CODE_DIRS) artifact_prefixes = tuple(path.join(directory, '') for directory in ARTIFACT_CODE_DIRS)
# Snapshot: another thread, or a lazy module's `__getattr__`, may import mid-scan.
evicted = [ evicted = [
name name
for name, module in list(sys.modules.items()) for name, module in sys.modules.copy().items()
if name.partition('.')[0] in shipped if name.partition('.')[0] in shipped
# `__path__` covers namespace packages, which have no `__file__`. # `__path__` covers namespace packages, which have no `__file__`.
and any( and any(