Skip to content

fix: avoid InferenceError crash in slots() for annotation-only __slots__#3074

Open
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
fix-crash-3067
Open

fix: avoid InferenceError crash in slots() for annotation-only __slots__#3074
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
fix-crash-3067

Conversation

@Pierre-Sassoulas
Copy link
Copy Markdown
Member

Type of Changes

Type
🐛 Bug fix

Description

_islots checks for __slots__ in locals and then infers it via igetattr. When __slots__ is declared as a bare annotation with no value (e.g. __slots__: None), it is present in locals but cannot be inferred, so igetattr raised an InferenceError that escaped slots(). Treat such a __slots__ as not inferable and return None.

Closes #3067

``_islots`` checks for ``__slots__`` in ``locals`` and then infers it via
``igetattr``. When ``__slots__`` is declared as a bare annotation with no
value (e.g. ``__slots__: None``), it is present in ``locals`` but cannot
be inferred, so ``igetattr`` raised an ``InferenceError`` that escaped
``slots()``. Treat such a ``__slots__`` as not inferable and return None.

Closes #3067
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.2.0 milestone May 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.53%. Comparing base (056f9ff) to head (9d32517).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3074   +/-   ##
=======================================
  Coverage   93.52%   93.53%           
=======================================
  Files          92       92           
  Lines       11329    11333    +4     
=======================================
+ Hits        10596    10600    +4     
  Misses        733      733           
Flag Coverage Δ
linux 93.39% <100.00%> (+<0.01%) ⬆️
pypy 93.53% <100.00%> (+<0.01%) ⬆️
windows 93.50% <100.00%> (+<0.01%) ⬆️

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.34% <100.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeInferenceError: '__slots__' not found on ClassDef node

1 participant