Title: Self is not rejected when used as a PEP 695 type parameter bound · Issue #21960 · python/mypy · GitHub
Open Graph Title: Self is not rejected when used as a PEP 695 type parameter bound · Issue #21960 · python/mypy
X Title: Self is not rejected when used as a PEP 695 type parameter bound · Issue #21960 · python/mypy
Description: Bug Report Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations. See: mypy/test-data/unit/check-selftype.test Line 1480 in ae39cdb [case testTypingSelfInvalidLocations] It seem...
Open Graph Description: Bug Report Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations. See: mypy/test-data/unit/check-selftype.test Line 1480 in ae39cdb [case...
X Description: Bug Report Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations. See: mypy/test-data/unit/check-selftype.test Line 1480 in ae39cdb [case...
Opengraph URL: https://github.com/python/mypy/issues/21960
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Self is not rejected when used as a PEP 695 type parameter bound","articleBody":"### Bug Report\n\nSelf is only valid in the specific locations listed in [PEP 673](https://peps.python.org/pep-0673/#valid-locations-for-self) and Mypy already rejects several invalid locations.\nSee: https://github.com/python/mypy/blob/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc/test-data/unit/check-selftype.test#L1480\n\nIt seems one location wasn't covered: using Self as the bound (or constraint) of a PEP 695 type parameter.\n\n### To Reproduce:\n```python\nfrom typing import Self\nclass Foo:\n def fails[T: Self](self: T) -> None: pass\n```\n### Expected Behavior\n\nMypy should reject `Self` here with an error.\n\nFrom a quick look at other type checkers: pyright and ty treat it as an invalid/generic TypeVar bound (`TypeVar upper bound cannot be generic`), while zuban rejects it with the same message mypy already uses elsewhere,\n```Self type is only allowed in annotations within class definition```.\n\n\n### Actual Behavior\nNo error is reported.\n\n### Your Environment\n\nMypy version: https://github.com/python/mypy/commit/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc\nPython version: 3.12\n\nTLDR; originally spotted while working on #21928 See: https://github.com/python/mypy/pull/21928#issuecomment-5557910054","author":{"url":"https://github.com/EmmanuelNiyonshuti","@type":"Person","name":"EmmanuelNiyonshuti"},"datePublished":"2026-09-08T21:42:46Z","url":"https://github.com/python/mypy/issues/21960"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a02e5706-fe8a-c464-4615-2c2d4a522c4a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE1A:B5253:1620DAD:1D415EC:6B001DD1 |
| html-safe-nonce | 94eae1e1122826a7da6851a9f77ad6dfae2bcdb49dd226c199609ec507a3e58d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTFBOkI1MjUzOjE2MjBEQUQ6MUQ0MTVFQzo2QjAwMUREMSIsInZpc2l0b3JfaWQiOiI0NDU1NjUzMDQwOTI5NjQzOTg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ccb732a40b0cbad3340f106cd5897ed488eac8bc3f62a77e9e1a144538e602fa |
| hovercard-subject-tag | issue:5392211569 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/21960/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b21d7a66edc311036b5ac11bf69f6f05e62bdbdef9788aa78d4796a537887385/python/mypy/issues/21960 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b21d7a66edc311036b5ac11bf69f6f05e62bdbdef9788aa78d4796a537887385/python/mypy/issues/21960 |
| og:image:alt | Bug Report Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations. See: mypy/test-data/unit/check-selftype.test Line 1480 in ae39cdb [case... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EmmanuelNiyonshuti |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width