Skip to content

Reject Self in PEP 695 type parameter bounds - #21961

Open
wolfgang-aura wants to merge 2 commits into
python:masterfrom
wolfgang-aura:mailman/issue-21960
Open

Reject Self in PEP 695 type parameter bounds#21961
wolfgang-aura wants to merge 2 commits into
python:masterfrom
wolfgang-aura:mailman/issue-21960

Conversation

@wolfgang-aura

Copy link
Copy Markdown

Closes #21960.

Mypy accepts Self as the bound of a PEP 695 type parameter, even though
Self is only valid in the locations defined by PEP 673. The same path also
fails to apply the existing Self validation consistently to constraints.

The cause was that PEP 695 bounds and constraints were analyzed without the
existing prohibit_self_type context. The fix passes the appropriate
prohibition context through both paths and adds regression coverage to the
existing invalid-Self test case.

How this was tested

At the reported base commit ae39cdb2fba8908eeff6ec8d6b88879c62495fcc, the
machine-checked reproduction accepted the invalid bound with
mypy_exit=0 and diagnostics=0. After the change, the final independent
verification 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_type context keeps bound,
constraint, nested, and typing_extensions.Self handling on one validation
path and avoids duplicate diagnostics logic.

AI disclosure

This change was drafted with AI assistance: codex (gpt-5.6-luna) wrote the
patch and codex (gpt-5.6-luna) reviewed it under Mailman. The test results
above were executed by the Mailman harness. Human review and filing remain
pending.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

Self is not rejected when used as a PEP 695 type parameter bound

1 participant