Skip to content

fix: check hasattr(qname) before calling in is_abstract#3141

Open
muhamedfazalps wants to merge 3 commits into
pylint-dev:mainfrom
muhamedfazalps:fix/typevar-qname-error
Open

fix: check hasattr(qname) before calling in is_abstract#3141
muhamedfazalps wants to merge 3 commits into
pylint-dev:mainfrom
muhamedfazalps:fix/typevar-qname-error

Conversation

@muhamedfazalps

Copy link
Copy Markdown
Contributor

Fixes #3086

The is_abstract method called inferred.qname() without checking if the object has a qname() method. When a TypeVar is used as a decorator, inferred is a TypeVar object which doesn't have qname(), causing an AttributeError.

This fix adds hasattr(inferred, 'qname') check before calling qname().

---\n\nbuymeacoffee.com/muhamedfazalps

When prefer_stubs is True, the code now checks for .pyi files first
before returning the original file (e.g., .pyc). This ensures .pyi
stubs take precedence over compiled bytecode files, fixing a regression
where .pyi files were no longer recognized.

Fixes pylint-dev#3087
@codspeed-hq

codspeed-hq Bot commented Jul 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing muhamedfazalps:fix/typevar-qname-error (cff3f12) with main (cf34ca7)

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.

The is_abstract method called inferred.qname() without checking if the
object has a qname() method. When a TypeVar is used as a decorator,
inferred is a TypeVar object which doesn't have qname(), causing an
AttributeError.

This fix adds hasattr(inferred, 'qname') check before calling qname().

Fixes pylint-dev#3086
@muhamedfazalps muhamedfazalps force-pushed the fix/typevar-qname-error branch from 1536e93 to 4dd39b2 Compare July 12, 2026 05:42
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.59%. Comparing base (cf34ca7) to head (cff3f12).

Files with missing lines Patch % Lines
astroid/modutils.py 33.33% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3141      +/-   ##
==========================================
- Coverage   93.62%   93.59%   -0.04%     
==========================================
  Files          92       92              
  Lines       11383    11389       +6     
==========================================
+ Hits        10657    10659       +2     
- Misses        726      730       +4     
Flag Coverage Δ
linux 93.45% <42.85%> (-0.04%) ⬇️
pypy 93.59% <42.85%> (-0.04%) ⬇️
windows 93.56% <42.85%> (-0.04%) ⬇️

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.28% <100.00%> (ø)
astroid/modutils.py 88.17% <33.33%> (-1.21%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix by implementing qname on TypeVar

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