Skip to content

fix: avoid TypeError crash for functional Enum with non-string member#3072

Draft
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
fix-crash-3068
Draft

fix: avoid TypeError crash for functional Enum with non-string member#3072
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
fix-crash-3068

Conversation

@Pierre-Sassoulas
Copy link
Copy Markdown
Member

Type of Changes

Type
🐛 Bug fix

Description

infer_func_form filters whitespace out of member names with " " not in attr, assuming every attribute is a string. A functional Enum call such as Enum("e", (1,)) yields an integer member name, making that check raise TypeError. Such a definition is invalid, so raise UseInferenceDefault and let inference fall back instead.

Closes #3068

``infer_func_form`` filters whitespace out of member names with
``" " not in attr``, assuming every attribute is a string. A functional
``Enum`` call such as ``Enum("e", (1,))`` yields an integer member name,
making that check raise ``TypeError``. Such a definition is invalid, so
raise ``UseInferenceDefault`` and let inference fall back instead.

Closes #3068
@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 (4c52ec5).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3072   +/-   ##
=======================================
  Coverage   93.52%   93.53%           
=======================================
  Files          92       92           
  Lines       11329    11331    +2     
=======================================
+ Hits        10596    10598    +2     
  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/brain/brain_namedtuple_enum.py 93.21% <100.00%> (+0.04%) ⬆️
🚀 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.

TypeError: argument of type 'int' is not a container or iterable with non-string enum attribute

1 participant