Title: [1.16 regression] Incorrect inferred type when using a classmethod from a different class as an attribute · Issue #19146 · python/mypy · GitHub
Open Graph Title: [1.16 regression] Incorrect inferred type when using a classmethod from a different class as an attribute · Issue #19146 · python/mypy
X Title: [1.16 regression] Incorrect inferred type when using a classmethod from a different class as an attribute · Issue #19146 · python/mypy
Description: Hello, I decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug. Let's say you have the following code (makes more sense in the concrete example it comes from) from collections.abc import ...
Open Graph Description: Hello, I decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug. Let's say you have the following code (makes more sense in the concrete example it ...
X Description: Hello, I decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug. Let's say you have the following code (makes more sense in the concrete example...
Opengraph URL: https://github.com/python/mypy/issues/19146
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.16 regression] Incorrect inferred type when using a classmethod from a different class as an attribute","articleBody":"Hello,\n\nI decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug.\n\nLet's say you have the following code (makes more sense in the concrete example it comes from)\n\n```\nfrom collections.abc import Iterable\nfrom typing import Protocol\n\n\nclass GetActions(Protocol):\n def __call__(self, event_type: str) -> Iterable[str]: ...\n\n\nclass Parent:\n get_actions: GetActions\n\n\nclass ActionsGetter:\n @classmethod\n def get_actions(self, event_type: str) -> Iterable[str]:\n return (\"1\",)\n\n\nclass Child(Parent):\n get_actions = ActionsGetter.get_actions\n\n\nprint(Child().get_actions(\"one\"))\n```\n\nThis works at runtime but at static time it complains with\n\n```\na.py:20: error: Incompatible types in assignment (expression has type \"Callable[[], Iterable[str]]\", base class \"Parent\" defined the type as \"GetActions\") [assignment]\na.py:20: note: \"GetActions.__call__\" has type \"Callable[[Arg(str, 'event_type')], Iterable[str]]\"\nFound 1 error in 1 file (checked 1 source file)\n```\n\nWhere it believes that the type of `Child.get_actions` is `Callable[[], Iterable[str]]` instead of `Callable[[Arg(str, 'event_type')], Iterable[str]]`\n\n\n**Your Environment**\n\n\n\n- Mypy version used: release-1.16 (revision 96525a23f, built locally with mypy_mypyc-wheels for cp312-macosx_arm64)\n- Mypy command-line flags: `mypy a.py`\n- Mypy configuration options from `mypy.ini` (and other config files): no config\n- Python version used: python3.12\n","author":{"url":"https://github.com/delfick","@type":"Person","name":"delfick"},"datePublished":"2025-05-24T02:17:45Z","url":"https://github.com/python/mypy/issues/19146"}
| 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:512200a2-91ef-c4bf-2c3c-81132d0008f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E298:1D5C28:FC3C2C:14B0B50:6AFFF8C1 |
| html-safe-nonce | 4c958abf498e99731fccc2b37f977c3785e94d6d72371304e6494851fd0b7eb5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjk4OjFENUMyODpGQzNDMkM6MTRCMEI1MDo2QUZGRjhDMSIsInZpc2l0b3JfaWQiOiI4NDU5NTM5Mzc4MDk4NjY1NjY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bf96f0a3013fab3995ac0eea21c740706ddd6a08b250e627c1e4ad0790befa0f |
| hovercard-subject-tag | issue:3087907405 |
| 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/19146/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f64b1df9240e7961852c29d2fade3c532d7575dd8933ea8e586e2cc3263dc5bf/python/mypy/issues/19146 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f64b1df9240e7961852c29d2fade3c532d7575dd8933ea8e586e2cc3263dc5bf/python/mypy/issues/19146 |
| og:image:alt | Hello, I decided to try out the new mypy 1.16 branch on the codebase I work on and I found what I think is a bug. Let's say you have the following code (makes more sense in the concrete example it ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | delfick |
| 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