Title: MyPy does not support subclassing function a argument member with type `type` though pyright does (e.g. pyright 1.1.414) · Issue #22337 · python/mypy · GitHub
Open Graph Title: MyPy does not support subclassing function a argument member with type `type` though pyright does (e.g. pyright 1.1.414) · Issue #22337 · python/mypy
X Title: MyPy does not support subclassing function a argument member with type `type` though pyright does (e.g. pyright 1.1.414) · Issue #22337 · python/mypy
Description: Hello MyPy team. Thanks for the great tool. Sharing the following behavior which appears inconsistent with handling of arguments of type type (normally can be subclassed) and which is inconsistent with the other popular typechecker Pyrig...
Open Graph Description: Hello MyPy team. Thanks for the great tool. Sharing the following behavior which appears inconsistent with handling of arguments of type type (normally can be subclassed) and which is inconsistent ...
X Description: Hello MyPy team. Thanks for the great tool. Sharing the following behavior which appears inconsistent with handling of arguments of type type (normally can be subclassed) and which is inconsistent ...
Opengraph URL: https://github.com/python/mypy/issues/22337
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MyPy does not support subclassing function a argument member with type `type` though pyright does (e.g. pyright 1.1.414)","articleBody":"Hello MyPy team. Thanks for the great tool.\nSharing the following behavior which appears inconsistent with handling of arguments of type `type` (normally can be subclassed) and which is inconsistent with the other popular typechecker Pyright (e.g. commandline pyright 1.1.414 ; or latest on pyright-play.net )\n\n**Bug Report**\n\nMyPy does not support subclassing function a argument member with type `type` though pyright does.\n\nConsider the following example in the Pyright playground (typechecks there):\nCode sample in [pyright playground](https://pyright-play.net/?code=MYGwhgzhAEAKCmAnCB7AdgCgJQC4BQ0h0AJvAGbQD6lAlmjQC7UYTwhkA00aYAtvDmgQGiLmADmA6HQZdgACzCIwwBkhrCawCIIYBPAA7xcBIoVbsAdD37QAvNz7xTZi2UsT496J5dE3lgpKKmqIGgxaMA5Byqrqmtp4eKQUZCgoGEbI6III2WhY0AC0AHzQAHLoAn6I8ABu8GAglPpGmUioaIGKsaHhkVh%2BoJAwAMoArgBG7fndwXFhCRC40AYjQA)\n\n```python\nclass Person():\n def __init__(self, name: str, age: int, characteristics: type):\n self.name = name\n self.age = age\n self.characteristics = characteristics\n\ndef foo(person: Person) -> None:\n reveal_type(person.characteristics)\n class Sub(person.characteristics): pass\n```\n\n\n\u003cimg width=\"1480\" height=\"876\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/85cdf631-278c-45d8-a85a-9a2f08ba3833\" />\n\nIf one attempts the same in MyPy 2.4.1\nMyPy produces an error attempting to subclass `person.characteristics` though MyPy recognizes the type as `builtins.type`:\nhttps://mypy-play.net/?mypy=2.4.1&python=3.12&gist=0ecda4fd36c9338c128ae16e69750463\n```python\nclass Person():\n def __init__(self, name: str, age: int, characteristics: type):\n self.name = name\n self.age = age\n self.characteristics = characteristics\n\ndef foo(person: Person) -> None:\n reveal_type(person.characteristics) # N: Revealed type is \"builtins.type\"\n class Sub(person.characteristics): pass\n```\n\noutput:\n```\nmain.py:8: note: Revealed type is \"type\"\nmain.py:9: error: Name \"person.characteristics\" is not defined [name-defined]\n```\n\n(MyPy reveals the type of `person.characteristics` successfully but says the name is undefined when attempting to subclass)\n\n\u003cimg width=\"1480\" height=\"876\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/2198350d-5c05-4f35-bc1e-d50f5e4656a7\" />\n\n(And the same on the latest master\n\n\u003cimg width=\"1480\" height=\"893\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/b2fbc49e-5b11-433d-8049-f4b7fea59466\" />\n)\n\nThis is despite subclassing arguments of type `type` being generally supported, e.g.\nhttps://mypy-play.net/?mypy=latest&python=3.12&gist=40c549b7acb527d213518171db016ca7\n```python\ndef foo(a_type: type) -> None:\n reveal_type(a_type) # N: Revealed type is \"builtins.type\"\n class Sub(a_type): pass\n```\n\nis fine in MyPy 2.4.1 .\n\n\u003cimg width=\"1480\" height=\"893\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/420d8a5e-c73d-4b4e-b4bd-8d25bbfe5a7c\" />\n\nThanks!\n\n**Your Environment**\n\n- Mypy version used: 2.4.1 and latest master (see https://mypy-play.net/?mypy=2.4.1&python=3.12&gist=0ecda4fd36c9338c128ae16e69750463 )\n- Mypy command-line flags: see mypy playground link https://mypy-play.net/?mypy=2.4.1&python=3.12&gist=0ecda4fd36c9338c128ae16e69750463\n- Mypy configuration options from `mypy.ini` (and other config files): see mypy playground, https://mypy-play.net/?mypy=2.4.1&python=3.12&gist=0ecda4fd36c9338c128ae16e69750463 \n- Python version used: 3.12\n\nThanks","author":{"url":"https://github.com/willy-b","@type":"Person","name":"willy-b"},"datePublished":"2026-10-31T18:09:15Z","url":"https://github.com/python/mypy/issues/22337"}
| 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:cb78f265-fe37-83ff-96c9-008a9dbf7035 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAC2:44D65:248CE6:313048:6B002400 |
| html-safe-nonce | bbb774ac495512ee112134b9c5bc6bfdf138a4ce9df4ef9040f7fddde7e6ac4c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUMyOjQ0RDY1OjI0OENFNjozMTMwNDg6NkIwMDI0MDAiLCJ2aXNpdG9yX2lkIjoiNDU5NTQzNTkyOTg1Mzc2NDYwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 679fcd38dc6892f4f972f0a5e17f09bb9d4f3193f8f932419918f6bf1949ead8 |
| hovercard-subject-tag | issue:6138130337 |
| 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/22337/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f38e456c3b56be5ac094ddf477a40abdc66f54a86cac0933faca06d07cf171e6/python/mypy/issues/22337 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f38e456c3b56be5ac094ddf477a40abdc66f54a86cac0933faca06d07cf171e6/python/mypy/issues/22337 |
| og:image:alt | Hello MyPy team. Thanks for the great tool. Sharing the following behavior which appears inconsistent with handling of arguments of type type (normally can be subclassed) and which is inconsistent ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | willy-b |
| 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