Title: Type aliases in class definitions · Issue #9238 · python/mypy · GitHub
Open Graph Title: Type aliases in class definitions · Issue #9238 · python/mypy
X Title: Type aliases in class definitions · Issue #9238 · python/mypy
Description: Under MyPy 0.780, the code from typing import List class ABC: ABCInputType = List x: ABC.ABCInputType = [] throws test.py:6: error: Variable "test.ABC.ABCInputType" is not valid as a type test.py:6: note: See https://mypy.readthedocs.io/...
Open Graph Description: Under MyPy 0.780, the code from typing import List class ABC: ABCInputType = List x: ABC.ABCInputType = [] throws test.py:6: error: Variable "test.ABC.ABCInputType" is not valid as a type test.py:6...
X Description: Under MyPy 0.780, the code from typing import List class ABC: ABCInputType = List x: ABC.ABCInputType = [] throws test.py:6: error: Variable "test.ABC.ABCInputType" is not valid as a type...
Opengraph URL: https://github.com/python/mypy/issues/9238
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type aliases in class definitions","articleBody":"Under MyPy 0.780, the code\r\n\r\n```python\r\nfrom typing import List\r\n\r\nclass ABC:\r\n ABCInputType = List\r\n\r\nx: ABC.ABCInputType = []\r\n```\r\n\r\nthrows\r\n\r\n```\r\ntest.py:6: error: Variable \"test.ABC.ABCInputType\" is not valid as a type\r\ntest.py:6: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nwhile\r\n\r\n```python\r\nfrom typing import List\r\n\r\nABCInputType = List\r\n\r\nx: ABCInputType = []\r\n```\r\n\r\nworks just fine.\r\n\r\nThe use of type aliases in classes seems both like a pretty legitimate use case to me (consider for example the ability to have an input type for the class as an attribute of the class as above) and also seems consistent with both the [`typing` documentation](https://docs.python.org/3/library/typing.html#type-aliases) and [`mypy`'s documentation](https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases), neither of which seem to mention that type aliases can only appear at the top level (only that they need to be plain assignments, as they are in the above code).","author":{"url":"https://github.com/evhub","@type":"Person","name":"evhub"},"datePublished":"2020-07-31T21:01:10Z","url":"https://github.com/python/mypy/issues/9238"}
| 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:96eae10c-1f9e-8b4c-2c0e-ac5fe6ace7b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7AC:14B836:453276:5D2CD6:6B002C81 |
| html-safe-nonce | c42ed40c16f597224aaac23f36e7966f6617bfe583abccfa276f762539241914 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0FDOjE0QjgzNjo0NTMyNzY6NUQyQ0Q2OjZCMDAyQzgxIiwidmlzaXRvcl9pZCI6IjQzMzU5NDc1NDM1NjYzNjM3NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | df89808734efd38f41c1f3ff6a1b07740ddb48de109207c658205fd874d62d8b |
| hovercard-subject-tag | issue:670229792 |
| 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/9238/issue_layout |
| twitter:image | https://opengraph.githubassets.com/724fd879577a4a750b25feb08f15fe643ad2b8a577b08bdaf8a2f4a69d269909/python/mypy/issues/9238 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/724fd879577a4a750b25feb08f15fe643ad2b8a577b08bdaf8a2f4a69d269909/python/mypy/issues/9238 |
| og:image:alt | Under MyPy 0.780, the code from typing import List class ABC: ABCInputType = List x: ABC.ABCInputType = [] throws test.py:6: error: Variable "test.ABC.ABCInputType" is not valid as a type test.py:6... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | evhub |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width