Fix pyreverse crash on classes with EmptyNode instance attrs - #11278
Fix pyreverse crash on classes with EmptyNode instance attrs#11278aryansk wants to merge 3 commits into
Conversation
A function's type parameters (PEP 695) are scoped to the function, so reusing a type-parameter name from an outer scope (e.g. a type alias) is a common idiom and should not trigger redefined-outer-name (W0621). Skip names that are type parameters of the current function in visit_functiondef, add a functional regression test, and update the used_before_assignment_py312/py313 functional tests that previously documented this false positive. Closes pylint-dev#11169.
The Linker's visit_classdef skipped `nodes.Unknown` placeholders but not `nodes.EmptyNode`, which astroid's namedtuple/argparse brains inject into `instance_attrs` of rebuilt classes. The relationship handlers then dereferenced `.name` on the placeholder and crashed. Skip both placeholder types when extracting composition/association relationships. Closes pylint-dev#10767
for more information, see https://pre-commit.ci
|
Reproduced the crash on main; this patch clears it. Regression from #10397 (1abd975): at That turns |
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Let's remove the unrelated changes in redfined-outer-name please.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11278 +/- ##
==========================================
+ Coverage 96.40% 96.44% +0.04%
==========================================
Files 178 178
Lines 20020 20023 +3
==========================================
+ Hits 19300 19311 +11
+ Misses 720 712 -8
🚀 New features to boost your workflow:
|
Description
Fixes #10767
pyreversecrashes withAttributeError: 'EmptyNode' object has no attribute 'name'when a class diagram includes a class whoseinstance_attrscontain syntheticEmptyNodeentries. Astroid injects these placeholders when rebuilding certain classes — e.g. namedtuple results (thenamedtuplebrain setsattrnameonEmptyNodenodes) andargparse.Namespaceinference results.The
Linker.visit_classdefguarded againstnodes.Unknownplaceholders but notnodes.EmptyNode, so the placeholder was passed into the composition/aggregation/association relationship handlers, which dereferenced.nameand crashed.This change skips both placeholder types when extracting relationships.
Type of Changes
Related Issue
Closes #10767