Skip to content

fix: guard is_abstract against decorators without qname#3089

Open
SAY-5 wants to merge 4 commits into
pylint-dev:mainfrom
SAY-5:fix/is-abstract-typevar-qname
Open

fix: guard is_abstract against decorators without qname#3089
SAY-5 wants to merge 4 commits into
pylint-dev:mainfrom
SAY-5:fix/is-abstract-typevar-qname

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 31, 2026

Copy link
Copy Markdown
Contributor

Closes #3086.

FunctionDef.is_abstract calls inferred.qname() unconditionally on each inferred decorator, but PEP 695 TypeVar nodes don't expose qname. Decorating a method with a class-scoped type variable (e.g. class C[T]: @T def m(): ...) crashes is_abstract with AttributeError: 'TypeVar' object has no attribute 'qname', propagating up through pylint's class_is_abstract check. Skip decorators that don't expose qname so unrelated decorator shapes don't kill the abstract check.

SAY-5 and others added 3 commits May 30, 2026 20:47
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.58%. Comparing base (1f3b8fa) to head (15ee061).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
linux 93.45% <100.00%> (-0.02%) ⬇️
pypy 93.58% <100.00%> (-0.02%) ⬇️
windows 93.55% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/nodes/scoped_nodes/scoped_nodes.py 93.20% <100.00%> (-0.08%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaoflow

gaoflow commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Thanks for fixing this. Heads-up that the same unguarded qname() call exists at a second site this PR doesn't cover, so #3086's crash still reproduces through plain inference after this lands. FunctionDef.decoratornames() (scoped_nodes.py:1463) does result.add(infnode.qname()) for each inferred decorator:

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 is_abstract would work there too. Might be worth covering both sites in this PR so #3086 is fully closed; otherwise I'm happy to send a follow-up PR scoped to decoratornames once this merges.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5

SAY-5 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

@gaoflow

gaoflow commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Nice, that's the site I had in mind. With both is_abstract and the decoratornames loop guarded, #3086 should be fully covered now. Thanks for the quick turnaround.

@codspeed-hq

codspeed-hq Bot commented Jun 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing SAY-5:fix/is-abstract-typevar-qname (15ee061) with main (1d38251)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'TypeVar' object has no attribute 'qname' in is_abstract

2 participants