Title: self: Ident[Self] wrongly rejected for an identity type alias (type Ident[T] = T). · Issue #22181 · python/mypy · GitHub
Open Graph Title: self: Ident[Self] wrongly rejected for an identity type alias (type Ident[T] = T). · Issue #22181 · python/mypy
X Title: self: Ident[Self] wrongly rejected for an identity type alias (type Ident[T] = T). · Issue #22181 · python/mypy
Description: Bug Report Mypy reports "Method cannot have explicit self annotation and Self type [misc]" when self or cls are annotated with Ident[Self] where type Ident[T] = T. Since Ident[Self] = Self mypy should accept annotations of Ident[Self]. T...
Open Graph Description: Bug Report Mypy reports "Method cannot have explicit self annotation and Self type [misc]" when self or cls are annotated with Ident[Self] where type Ident[T] = T. Since Ident[Self] = Self mypy sho...
X Description: Bug Report Mypy reports "Method cannot have explicit self annotation and Self type [misc]" when self or cls are annotated with Ident[Self] where type Ident[T] = T. Since Ident[Self] = Sel...
Opengraph URL: https://github.com/python/mypy/issues/22181
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"self: Ident[Self] wrongly rejected for an identity type alias (type Ident[T] = T).","articleBody":"**Bug Report**\n\nMypy reports \"Method cannot have explicit self annotation and Self type [misc]\" when self or cls are annotated with Ident[Self] where ```type Ident[T] = T```. Since Ident[Self] = Self mypy should accept annotations of Ident[Self]. This also affects ```type Anno[T] = Annotated[T, '']```. Pyright and ty don't report any errors in either case.\n\nThis issue is similar to #21917 and I explicitly noted it in #21928.\n\n**To Reproduce**\n\n```python\nfrom typing import Self, Annotated\n\ntype Ident[T] = T\n\ntype Anno[T] = Annotated[T, \"\"]\n\nclass C:\n def foo(self: Ident[Self], x: int) -> None:\n ...\n\n @classmethod\n def bar(cls: Ident[type[Self]], x: int) -> None:\n ...\n\n @classmethod\n def baz(cls: type[Ident[Self]], x: int) -> None:\n ...\n \n def anno(self: Anno[Self], x: int) -> None:\n ...\n```\nhttps://mypy-play.net/?gist=6a1c9a95a6ddd12ead7d71cffdf39ac6\n\n**Actual Behavior**\n\nmypy reports:\nmain.py:8: error: Method cannot have explicit self annotation and Self type [misc]\nmain.py:12: error: Method cannot have explicit self annotation and Self type [misc]\nmain.py:16: error: Method cannot have explicit self annotation and Self type [misc]\nmain.py:19: error: Method cannot have explicit self annotation and Self type [misc]\nFound 4 errors in 1 file (checked 1 source file)\n\n**My Environment**\n\n- Mypy version used: current master as of 26/10/11, latest release 2.4.0\n- Mypy command-line flags: None\n- Mypy configuration options from `mypy.ini` (and other config files): None\n- Python version used: 3.12\n","author":{"url":"https://github.com/Moussa-Mikhail","@type":"Person","name":"Moussa-Mikhail"},"datePublished":"2026-10-12T00:57:13Z","url":"https://github.com/python/mypy/issues/22181"}
| 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:ec4ed55d-ec68-c3bd-8b4c-0901dbdcdf6c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B208:9E1B2:2595D63:311192B:6AFFF7DD |
| html-safe-nonce | 2112d0f16af394af8e6a7769e923274ba1d63de62423cae947c61d5a9cd44b7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjA4OjlFMUIyOjI1OTVENjM6MzExMTkyQjo2QUZGRjdERCIsInZpc2l0b3JfaWQiOiI2MDM5NDU1MDU3NzY0Njc3NTk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 57cf40015254608fde58762270fae3a91e59b8e515e8698268f53a84488bcebc |
| hovercard-subject-tag | issue:5806837047 |
| 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/22181/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e04d04199b75dbc2bbf1f1f66b96f6eba78b1945dda6770b1da2fb503a119c69/python/mypy/issues/22181 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e04d04199b75dbc2bbf1f1f66b96f6eba78b1945dda6770b1da2fb503a119c69/python/mypy/issues/22181 |
| og:image:alt | Bug Report Mypy reports "Method cannot have explicit self annotation and Self type [misc]" when self or cls are annotated with Ident[Self] where type Ident[T] = T. Since Ident[Self] = Self mypy sho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Moussa-Mikhail |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width