Skip to content

Fix instance_attrs typing and two bugs pyright found with it - #3411

Merged
Pierre-Sassoulas merged 6 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:pyright-locals-types
Oct 21, 2026
Merged

Pierre-Sassoulas merged 6 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:pyright-locals-types

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Type of Changes

Type
✓ 🐛 Bug fix

Description

ClassDef.instance_attrs was annotated as a dict of nodes, but it holds lists like on FunctionDef and Lambda. All three now use the value type of locals, list[InferenceResult], so brains can store any inferred node.

With the right type, pyright found two bugs:

  • FunctionDef.getattr and Lambda.getattr appended the special attribute to the list stored in instance_attrs instead of to a copy, so the list grew by one each time an attribute such as name was looked up.
  • ClassDef._other_other_fields was the string "locals" instead of a tuple, so ClassDef.repr_tree(ast_state=True) raised AttributeError.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.4.0 milestone Oct 19, 2026
@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing Pierre-Sassoulas:pyright-locals-types (a573763) with main (af39fd7)

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. ↩

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.01%. Comparing base (ee30b02) to head (a573763).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3411      +/-   ##
==========================================
+ Coverage   90.96%   91.01%   +0.05%     
==========================================
  Files          93       93              
  Lines       11796    11800       +4     
  Branches     1941     1939       -2     
==========================================
+ Hits        10730    10740      +10     
+ Misses        747      744       -3     
+ Partials      319      316       -3     
Flag Coverage Δ
linux 90.69% <99.04%> (+0.05%) ⬆️
pypy 91.01% <100.00%> (+0.05%) ⬆️
windows 90.85% <100.00%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
astroid/brain/brain_builtin_inference.py 91.39% <100.00%> (ø)
astroid/brain/brain_namedtuple_enum.py 92.30% <100.00%> (ø)
astroid/brain/brain_six.py 87.91% <100.00%> (ø)
astroid/brain/brain_type.py 100.00% <100.00%> (ø)
astroid/builder.py 92.64% <ø> (ø)
astroid/helpers.py 91.19% <100.00%> (ø)
astroid/inference_tip.py 95.55% <ø> (ø)
astroid/interpreter/_import/spec.py 93.20% <ø> (ø)
astroid/modutils.py 84.85% <100.00%> (ø)
astroid/nodes/_base_nodes.py 95.35% <100.00%> (ø)
... and 4 more

... and 1 file with indirect coverage changes

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

ClassDef.instance_attrs was annotated as a dict of nodes, but it holds
lists like on FunctionDef and Lambda. All three now use the value type
of locals, list[InferenceResult], so brains can store any inferred node.

With the right type, pyright found two bugs:

- FunctionDef.getattr and Lambda.getattr appended the special attribute
  to the list stored in instance_attrs instead of to a copy, so the list
  grew by one each time an attribute such as __name__ was looked up.
- ClassDef._other_other_fields was the string "locals" instead of a
  tuple, so ClassDef.repr_tree(ast_state=True) raised AttributeError.
@Pierre-Sassoulas
Pierre-Sassoulas merged commit 5395efb into pylint-dev:main Oct 21, 2026
37 checks passed
@Pierre-Sassoulas
Pierre-Sassoulas deleted the pyright-locals-types branch October 21, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants