Skip to content

Introduce the "bare"/"explictly typed" Final terminology - #2370

Open
srittau wants to merge 4 commits into
python:mainfrom
srittau:final-terms
Open

srittau wants to merge 4 commits into
python:mainfrom
srittau:final-terms

Conversation

@srittau

@srittau srittau commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

The main changes:

  • Reworked the "Syntax" section of the Final spec:
    • Define just two forms, one for each of the new terms.
    • The omitted right side syntax was folded into the "explicitly typed" syntax.
    • self.id: Final was moved to the semantics section where it fits better, since it's not a separate syntax.
  • Add the terms "bare Final" and "explicitly typed Final "to the glossary.

The rest of the changes use the new terms and link to the new glossary entries.

Closes: #2356

Comment thread docs/spec/dataclasses.rst

* 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`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 interprets Final itself as a type which is definitely buggy.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 jorenham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

Comment thread docs/spec/distributing.rst Outdated
Comment thread docs/spec/qualifiers.rst Outdated

@carljm carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment thread docs/spec/qualifiers.rst Outdated
srittau and others added 2 commits October 20, 2026 23:25
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spec: Final section could use better definition for Final vs. Final[X]

4 participants