Reject Self in PEP 695 type parameter bounds - #21961
Open
wolfgang-aura wants to merge 2 commits into
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Closes #21960.
Mypy accepts
Selfas the bound of a PEP 695 type parameter, even thoughSelfis only valid in the locations defined by PEP 673. The same path alsofails to apply the existing
Selfvalidation consistently to constraints.The cause was that PEP 695 bounds and constraints were analyzed without the
existing
prohibit_self_typecontext. The fix passes the appropriateprohibition context through both paths and adds regression coverage to the
existing invalid-
Selftest case.How this was tested
At the reported base commit
ae39cdb2fba8908eeff6ec8d6b88879c62495fcc, themachine-checked reproduction accepted the invalid bound with
mypy_exit=0anddiagnostics=0. After the change, the final independentverification selected the focused test case and reported
2 passed, 8225 deselected.The checks ran on Windows 11. Mailman recorded Python 3.14.3 for the host
command metadata; the target test environment used Python 3.12.14. Provider
integration testing was not part of this focused type-checker regression.
An alternative not taken
The error could have been added as a special case at each PEP 695 analysis
call site. Reusing the existing
prohibit_self_typecontext keeps bound,constraint, nested, and
typing_extensions.Selfhandling on one validationpath and avoids duplicate diagnostics logic.
AI disclosure
This change was drafted with AI assistance: codex (
gpt-5.6-luna) wrote thepatch and codex (
gpt-5.6-luna) reviewed it under Mailman. The test resultsabove were executed by the Mailman harness. Human review and filing remain
pending.