fix: guard is_abstract against decorators without qname#3089
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3089 +/- ##
==========================================
- Coverage 93.60% 93.58% -0.02%
==========================================
Files 92 92
Lines 11364 11365 +1
==========================================
- Hits 10637 10636 -1
- Misses 727 729 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Thanks for fixing this. Heads-up that the same unguarded import astroid
astroid.extract_node("class C[T]:\n @T\n def m(self): ... #@").inferred()
# AttributeError: 'TypeVar' object has no attribute 'qname'
# FunctionDef._infer -> bases._is_property -> decoratornames() (scoped_nodes.py:1463)(Verified on HEAD, 4.2.0b3.) The same guard you applied to |
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Good catch, thanks. Added the same guard to decoratornames (the result.add(infnode.qname()) loop) plus a regression test for the @T-decorated method case, so #3086 is fully covered now. Confirmed the test fails with AttributeError before the guard and passes after. |
|
Nice, that's the site I had in mind. With both |
Merging this PR will not alter performance
Comparing Footnotes
|
Closes #3086.
FunctionDef.is_abstractcallsinferred.qname()unconditionally on each inferred decorator, but PEP 695TypeVarnodes don't exposeqname. Decorating a method with a class-scoped type variable (e.g.class C[T]: @T def m(): ...) crashesis_abstractwithAttributeError: 'TypeVar' object has no attribute 'qname', propagating up through pylint'sclass_is_abstractcheck. Skip decorators that don't exposeqnameso unrelated decorator shapes don't kill the abstract check.