Skip to content

Conversation

@jacobtylerwalls
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Before, dataclass fields annotated with Final were treated like all other class variables annotated with Final and required to be uppercase. But that's not how dataclasses work -- you still want lower cased fields even if marked with Final. An exception would be ClassVar[Final], which doesn't give you a field.

Closes #10790

@jacobtylerwalls jacobtylerwalls added this to the 4.0.5 milestone Jan 3, 2026
@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/4.0.x C: invalid-name labels Jan 3, 2026
@codecov
Copy link

codecov bot commented Jan 3, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 95.99%. Comparing base (4f6c241) to head (4145bad).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10797   +/-   ##
=======================================
  Coverage   95.98%   95.99%           
=======================================
  Files         176      176           
  Lines       19564    19582   +18     
=======================================
+ Hits        18779    18797   +18     
  Misses        785      785           
Files with missing lines Coverage Ξ”
pylint/checkers/base/name_checker/checker.py 98.79% <100.00%> (+0.02%) ⬆️
pylint/checkers/utils.py 96.09% <100.00%> (+0.04%) ⬆️
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2026

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 4145bad

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review but I feared my lack of typing practice was a problem and that Marc would have a better opinion about this.

Comment on lines +23 to +24
field_annotated_with_final: Final[int] = 42
FIELD_ANNOTATED_WITH_FINAL: Final[int] = 42 # this could emit invalid-name eventually.
Copy link
Member

Choose a reason for hiding this comment

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

Reading PEP591 I felt that Final was supposed to indicate a constant. Note that most of the Final annotated variable are in UPPERCASE here : https://peps.python.org/pep-0591/#id2 (with a notable exception of the mutable list and a 2 int vector example). Also here in the "updated documentation" linked in PEP 591 : https://docs.python.org/3/library/typing.html#typing.Final. Could you explain your reasoning for forbidding uppercase ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I can remove the editorial comment. I don't think there's any plan to forbid upper cased final variables.

I replied to the reporter, if it helps:

I'm a little surprised we enforce snake_case for function variables annotated with Final, since it seems like they should be UPPER_CASE, which would conflict with the example here, but I take it we should just be liberal and allow either.

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

Labels

backport maintenance/4.0.x C: invalid-name False Positive 🦟 A message is emitted but nothing is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pylint C0103 (invalid-name) for dataclass Final field

2 participants