Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3468 +/- ##
=======================================
Coverage 91.23% 91.24%
=======================================
Files 93 93
Lines 11881 11889 +8
Branches 1960 1962 +2
=======================================
+ Hits 10840 10848 +8
Misses 732 732
Partials 309 309
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Comparing Footnotes
|
``infer_enum_class`` turned every assignment in an enum body into a member, including values wrapped in ``enum.nonmember()``. The name ended up in ``__members__``, so extending such a class made pylint report ``invalid-enum-extension``. Django 6 declares ``do_not_call_in_templates = enum.nonmember(True)`` on ``models.Choices``, so every ``models.Choices`` subclass in a Django 6 project hit it. Skip those assignments and leave the name as a plain class attribute.
Pierre-Sassoulas
force-pushed
the
fix-enum-nonmember-not-a-member
branch
from
November 20, 2026 22:18
eee012c to
0907d1e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Changes
Description
A value wrapped in
enum.nonmember()is not a member of the enum, butinfer_enum_classhandled it like any other assignment and listed it in__members__. pylint reads that dict in_check_enum_base, so extending such a class reportsinvalid-enum-extensionon valid code. Django 6.1.3 declaresdo_not_call_in_templates = enum.nonmember(True)onmodels.Choices, so an ordinary choices class in a Django 6 project fails:That is Django 6.1.3, pylint 4.1.3 and astroid
main(d5319a4) on Python 3.13.16, exit code 2. The problem was reported in a comment on pylint-dev/pylint#6887, which has a reproducer using only the standard library. I ran that one too: pylint reports E0244, and at runtimedict(MyEnum.__members__)holds only the real member.infer_enum_classnow skips an assignment whose value is a call toenum.nonmember, so the name stays a plain class attribute and stays out of__members__. The call is matched by name and confirmed with inference, so a local function that happens to be callednonmemberstill produces a member. With this branch and pylintmain(79c8d0c) the command above prints nothing and exits 0, and so do subclasses ofmodels.IntegerChoicesandmodels.TextChoices.Two things are unchanged. Reading the attribute back does not infer the wrapped value:
Base.LABEL.upper()withLABEL = enum.nonmember("label")getsno-memberbefore and after, and only the name in the message changes. An aliased import (from enum import nonmember as nm) is not recognised.Tests: three new tests in
tests/brain/test_enum.py. Without the new check ininfer_enum_class,test_enum_nonmember_is_not_a_memberfails withassert ['FLAG', 'ANNOTATED', 'RED'] == ['RED']andtest_enum_with_only_nonmembers_can_be_extendedfails on the non-empty__members__. The test for the local function passes either way, as it should.tests/brain,tests/test_inference.py,tests/test_scoped_nodes.py,tests/test_regrtest.pyandtests/test_object_model.pygive 1208 passed, 82 skipped, 15 xfailed. On pylintmainagainst this branch, the functional tests selected with-k enumgive 12 passed.ruff check,black --check,mypyand pylint with the repo'spylintrcare clean.All of that ran on Python 3.13 in a container. I did not run the rest of the astroid suite, the rest of pylint's tests, or pyright, and left those to CI.
Refs pylint-dev/pylint#6887
Closes #3467