Annotate 3.14+ ipaddress version / max_prefixlen as Literal - #16301
Open
ABruihler wants to merge 4 commits into
Open
Annotate 3.14+ ipaddress version / max_prefixlen as Literal#16301ABruihler wants to merge 4 commits into
version / max_prefixlen as Literal#16301ABruihler wants to merge 4 commits into
Conversation
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) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
ABruihler
marked this pull request as ready for review
August 26, 2026 20:07
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.
On 3.14+,
_BaseV4/_BaseV6declareversionandmax_prefixlenas bareFinals, so they inferas
Literal[4]?— an inferred literal that falls back toint— rather than a declaredLiteral[4]..versiontherefore no longer narrows anIPv4Network | IPv6Networkunion, which it does on 3.13where these are
Literal-returning properties, and that narrowing is the only type-safe way to reachsubnet_of/supernet_of/address_exclude, since they takeother: Self.Annotate the literal types explicitly, with
# noqa: PYI064because the bareFinalthat rulesuggests is precisely the form that loses the declared literal (pre-commit.ci autofixed it away in
0752a11, reverted in 44bc4e1). Happy to drop
Finaland use plainLiteral[4]instead if youwould rather not carry the
noqas, or to take this to ruff as a rule bug first.Agent used: Claude Code (Claude Opus 5).