More accurate test dependencies by ShaharNaveh · Pull Request #7261 · RustPython/RustPython
119-136:
frozenset return type breaks .discard() calls on result; causes AttributeError at runtime.
parse_lib_imports() and parse_test_imports() are annotated to return frozenset[str], but callers immediately call .discard() on the returned object (lines 1425, 1437). Since frozenset does not have a .discard() method, this raises AttributeError when parsing succeeds.
Additionally, the early-return statements (lines 132, 122) return set() instead of frozenset(), creating a type mismatch with the declared return type.
Fix: (1) Change early returns to frozenset(), (2) wrap parse_lib_imports() calls with set() at call sites that mutate the result:
imports = set(parse_lib_imports(content)) imports.discard(entry.stem)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/update_lib/deps.py` around lines 119 - 136, parse_lib_imports and
parse_test_imports are annotated to return frozenset but currently return
mutable set() on the early path and callers call .discard() on the result,
causing AttributeError; fix by making the functions consistently return
frozenset on the early-return path (replace set() with frozenset()) and do not
change the return type at the function level, and update call sites that need to
mutate the result (places that call .discard() on
parse_lib_imports/parse_test_imports results) to wrap the returned frozenset in
set(...) before mutating (e.g., imports = set(parse_lib_imports(content))); keep
references to ImportVisitor, parse_lib_imports, and parse_test_imports so you
can locate the code to change.