Title: False Positives in Protocol Assignability Check Where `Self` Is a Parameter of a Decorated Method (1.17.0) · Issue #19482 · python/mypy · GitHub
Open Graph Title: False Positives in Protocol Assignability Check Where `Self` Is a Parameter of a Decorated Method (1.17.0) · Issue #19482 · python/mypy
X Title: False Positives in Protocol Assignability Check Where `Self` Is a Parameter of a Decorated Method (1.17.0) · Issue #19482 · python/mypy
Description: Bug Report This bug appears to be a regression in mypy 1.17.0, version 1.16.1 works as expected. To Reproduce Consider the following code snippet: from typing import Protocol, Self class Proto(Protocol): def foo(self, x: Self) -> None: ....
Open Graph Description: Bug Report This bug appears to be a regression in mypy 1.17.0, version 1.16.1 works as expected. To Reproduce Consider the following code snippet: from typing import Protocol, Self class Proto(Prot...
X Description: Bug Report This bug appears to be a regression in mypy 1.17.0, version 1.16.1 works as expected. To Reproduce Consider the following code snippet: from typing import Protocol, Self class Proto(Prot...
Opengraph URL: https://github.com/python/mypy/issues/19482
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False Positives in Protocol Assignability Check Where `Self` Is a Parameter of a Decorated Method (1.17.0)","articleBody":"**Bug Report**\n\nThis bug appears to be a regression in `mypy` 1.17.0, version 1.16.1 works as expected.\n\n**To Reproduce**\n\nConsider the following code snippet:\n\n```python\nfrom typing import Protocol, Self\n\n\nclass Proto(Protocol):\n def foo(self, x: Self) -> None: ...\n\n\nclass Impl:\n def foo(self, x: Self) -> None:\n pass\n\n\nx: Proto = Impl()\n```\n\nThis is fine on both mypy 1.17.0 and 1.16.1. When we decorate `foo` in `Proto` (e.g., with `@abstractmethod`, `@deprecated`, or `@classmethod`), then the assignability check fails in `mypy` 1.17.0 only. Here are some snippets revealing the bug (the links use the `master` branch version because 1.17.0 is not available on mypy-play.net yet):\n\n- Using `@abstractmethod`: https://mypy-play.net/?mypy=master&python=3.13&gist=6ca38235427121b221eb1f2971c4205b\n- Using `@deprecated`: https://mypy-play.net/?mypy=master&python=3.13&gist=59bcf4be17a8924e7b1ba8df158daad6\n- Using `@classmethod`: https://mypy-play.net/?mypy=master&python=3.13&gist=18ab582214b1c2a87b9e99606f7fd15e\n- Using `@classmethod`, but with `Sequence[Self]`: https://mypy-play.net/?mypy=master&python=3.13&gist=9c335818a610c248a6546c090b0ac617\n\nI played around with some other variants:\n\n- The bug only shows if `Self` is used as the type of an argument. Using `Self` as a return type only is fine in 1.17.0.\n- When `Impl` declares compatibility with `Proto` explicitly (i.e., `class Impl(Proto)`), the bug does not show.\n- Whether `foo` in `Impl` is decorated or not does not appear to matter (only tested with `@deprecated`).\n- Whether `foo` in `Impl` has `x: Self` or `x: Impl` does not matter\n\n**Expected Behavior**\n\nThere should not be an error for all playground links above, as with `mypy` 1.16.1 or `pyright`.\n\n**Actual Behavior**\n\n`mypy` 1.17.0 shows errors like these (here for the example with `@abstractmethod`):\n\n main.py:18: error: Incompatible types in assignment (expression has type \"Impl\", variable has type \"Proto\") [assignment]\n main.py:18: note: Following member(s) of \"Impl\" have conflicts:\n main.py:18: note: Expected:\n main.py:18: note: def [Self: Proto] foo(self, x: Proto) -> None\n main.py:18: note: Got:\n main.py:18: note: def foo(self, x: Impl) -> None\n Found 1 error in 1 file (checked 1 source file)\n\n`mypy` 1.16.1 and `pyright` do not print any diagnostics.\n\n**Your Environment**\n\n- Mypy version used: 1.17.0 (bug) / 1.16.1 (expected behavior)\n- Mypy command-line flags: none\n- Mypy configuration options from `mypy.ini` (and other config files): none\n- Python version used: 3.13.5","author":{"url":"https://github.com/nhusung","@type":"Person","name":"nhusung"},"datePublished":"2025-07-20T10:23:54Z","url":"https://github.com/python/mypy/issues/19482"}
| 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:8560f2a2-06e7-6180-1316-b9655aa23822 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B552:392E27:DBBFBF:11EDC59:6AFFFA1D |
| html-safe-nonce | a89a1f9f4fbce6a34eb0218516ec57ad6e5bf5ef0b3152f2eb252de4974a44c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTUyOjM5MkUyNzpEQkJGQkY6MTFFREM1OTo2QUZGRkExRCIsInZpc2l0b3JfaWQiOiIzNzYyMDU0NDM4Njc2NTkzMTgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f78980e39a510e52fc468e72408655e1b0258c81cd7c972b74647767eb648488 |
| hovercard-subject-tag | issue:3246239853 |
| 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/19482/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f5c90d92d22a1a373f1e2cb748f998e90b65185c576afa40bd0758bf3ac95053/python/mypy/issues/19482 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f5c90d92d22a1a373f1e2cb748f998e90b65185c576afa40bd0758bf3ac95053/python/mypy/issues/19482 |
| og:image:alt | Bug Report This bug appears to be a regression in mypy 1.17.0, version 1.16.1 works as expected. To Reproduce Consider the following code snippet: from typing import Protocol, Self class Proto(Prot... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nhusung |
| 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