GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Finals and Literals: Spec contradiction · Issue #2351 · python/typing

Finals and Literals: Spec contradiction #2351

New issue
Copy link
New issue
Copy link
Open
#2353
Open
Finals and Literals: Spec contradiction#2351
#2353
Copy link
Labels
topic: conformance testsIssues with the conformance test suiteIssues with the conformance test suitetopic: typing specFor improving the typing specFor improving the typing spec

Description

@srittau
srittau
opened on Aug 31, 2026
Issue body actions

This came up in python/typeshed#16301. I assume this is mostly a clerical/historical error, but let me know if we should follow the whole spec change process.


The typing spec says about Final:

Example:

ID: Final = 1

The typechecker should apply its usual type inference mechanisms to determine the type of ID (here, likely, int).

And then a bit later:

Type checkers should treat uses of a final name that was initialized with a literal as if it was replaced by the literal.

Both sentences are copied directly from PEP 591, which overlapped with the Literals PEP 586.

I assume that we should change the first sentence to "here, likely, Literal[1]" and change the second sentence to be a bit more concrete along these lines:

Type checkers should infer uses of a final name that was initialized with a literal X as Literal[X] if X is an allowed literal type (cf. to the literals section). Otherwise, they should infer the type of the X.

(And maybe extend the example after a bit.)

In fact, this is what the conformance tests already check:

typing/conformance/tests/qualifiers_final_annotation.py

Lines 11 to 13 in cf943cc

ID2: Final = 1
assert_type(ID2, Literal[1])

(Although the tests could be extended a bit.)

Activity

  1. srittau
    added
    topic: typing specFor improving the typing specFor improving the typing spec
    on Aug 31, 2026
  2. carljm commented on Aug 31, 2026

    @carljm
    carljm
    on Aug 31, 2026
    Member
    More actions

    I do think a clarification to the spec text is warranted here; the current text is confusing. I think we should remove (here, likely, int) and instead mention the later "replacement" rule. And we should probably also clarify that the replacement rule applies to a bare Final annotation with valid literal initializer.

    I would consider this a spec clarification, not a change in specification.

  3. srittau commented on Aug 31, 2026

    @srittau
    srittau
    on Aug 31, 2026
    CollaboratorAuthor
    More actions

    As @carljm points out in #2352, the Literal section of the spec has a whole section about the interaction with Final that actually is already correct. We should probably just change the mentions in the Final spec part to point to that section.

    Reacted by Carl Meyer
  4. srittau
    added
    topic: conformance testsIssues with the conformance test suiteIssues with the conformance test suite
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: conformance testsIssues with the conformance test suiteIssues with the conformance test suitetopic: typing specFor improving the typing specFor improving the typing spec

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.