Repository navigation
Conversation
|
|
||
| * A dataclass field may be annotated with ``Final[...]``. For example, ``x: | ||
| Final[int]`` in a dataclass body specifies a dataclass field ``x``, which | ||
| * A dataclass field may be annotated with an :term:`explicitly typed Final` |
Member
There was a problem hiding this comment.
We may have to say what "bare Final" does in dataclasses. I discovered ty handles this buggily: astral-sh/ty#4766.
There are two cases:
- Bare Final with a default. The obvious interpretation is that that gives you a Final dataclass field with a literal type, which is coherent but kind of useless (you can only pass that one specific type).
- Bare Final without a default. Ty and pyrefly implement this like
Final[Any], which is sort of coherent but a little surprising to me; mypy disallows it; pyright interpretsFinalitself as a type which is definitely buggy.
Collaborator
Author
There was a problem hiding this comment.
Oh yes, I failed to mention that: Bare Finals in dataclasses are a thing, but were not mentioned by the specs. I wanted to keep the status quo in this PR, because it's not about that. I think this should be a separate discussion.
jorenham
reviewed
Oct 20, 2026
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
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.
The main changes:
Finalspec:self.id: Finalwas moved to the semantics section where it fits better, since it's not a separate syntax.The rest of the changes use the new terms and link to the new glossary entries.
Closes: #2356