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 — Annotate 3.14+ ipaddress `version` / `max_prefixlen` as `Literal` by ABruihler · Pull Request #16301 · python/typeshed

Conversation

@ABruihler

@ABruihler ABruihler commented Aug 26, 2026 •
edited by srittau
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

On 3.14+, _BaseV4 / _BaseV6 declare version and max_prefixlen as bare Finals, so they infer
as Literal[4]? — an inferred literal that falls back to int — rather than a declared Literal[4].
.version therefore no longer narrows an IPv4Network | IPv6Network union, which it does on 3.13
where these are Literal-returning properties, and that narrowing is the only type-safe way to reach
subnet_of / supernet_of / address_exclude, since they take other: Self.

Annotate the literal types explicitly, with # noqa: PYI064 because the bare Final that rule
suggests is precisely the form that loses the declared literal (pre-commit.ci autofixed it away in
0752a11, reverted in 44bc4e1). Happy to drop Final and use plain Literal[4] instead if you
would rather not carry the noqas, or to take this to ruff as a rule bug first.

Agent used: Claude Code (Claude Opus 5).


2026-08-31 (@srittau): Deferred pending discussion in python/typing#2351.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ABruihler and others added 2 commits August 26, 2026 15:44
@ABruihler @claude
Annotate 3.14+ ipaddress version / max_prefixlen as Literal
fa5a4fc
Declared as bare `Final`, they infer as `int`, so `.version` no longer
narrows an `IPv4Network | IPv6Network` union the way the pre-3.14
`Literal`-returning properties did.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
0752a11
@github-actions

This comment has been minimized.

Sign in to view
ABruihler and others added 2 commits August 26, 2026 16:00
@ABruihler @claude
Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"
44bc4e1
This reverts commit 0752a11. PYI064's autofix rewrites
`Final[Literal[4]] = 4` to a bare `Final`, which is exactly the form
that loses the declared literal type, so the fix undoes itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ABruihler @claude
Silence PYI064 on the explicit Literal annotations
5bd8c23
The rule's suggested bare `Final` is the form that loses the declared
literal type, so it cannot apply here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ABruihler
ABruihler marked this pull request as ready for review August 26, 2026 20:07
@srittau srittau mentioned this pull request Aug 31, 2026
Finals and Literals: Spec contradiction python/typing#2351
Open
@srittau

srittau commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

: Final = X is the pattern we generally use in typeshed. The typing spec says:

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

This text has been copied verbatim from PEP 591 This was released around the same the PEP 586 (Literals) was released, so this might simply be a case where two typing PEPs overlapped. This is supported by the following quote from the spec, 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.

(Also coming from PEP 591.)

The conformance tests also ensure that.

I've opened python/typing#2351, so let's wait for the feedback there.

ABruihler reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@srittau srittau added the status: deferred Issue or PR deferred until some precondition is fixed label Aug 31, 2026
@srittau
srittau marked this pull request as draft August 31, 2026 14:53

This branch has not been deployed

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

status: deferred Issue or PR deferred until some precondition is fixed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ABruihler @srittau
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.
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.