Title: Type variables bound by a generic class make no sense in static or class methods. · Issue #3172 · python/mypy · GitHub
Open Graph Title: Type variables bound by a generic class make no sense in static or class methods. · Issue #3172 · python/mypy
X Title: Type variables bound by a generic class make no sense in static or class methods. · Issue #3172 · python/mypy
Description: Here's a type variable in a normal method. This works fine: from typing import TypeVar, Generic T = TypeVar('T') class A(Generic[T]): def f(self) -> None: x: T However in a static method this doesn't make sense, since we don't have an in...
Open Graph Description: Here's a type variable in a normal method. This works fine: from typing import TypeVar, Generic T = TypeVar('T') class A(Generic[T]): def f(self) -> None: x: T However in a static method this doesn...
X Description: Here's a type variable in a normal method. This works fine: from typing import TypeVar, Generic T = TypeVar('T') class A(Generic[T]): def f(self) -> None: x: T However in a static me...
Opengraph URL: https://github.com/python/mypy/issues/3172
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type variables bound by a generic class make no sense in static or class methods.","articleBody":"Here's a type variable in a normal method. This works fine:\r\n\r\n```python\r\nfrom typing import TypeVar, Generic\r\n\r\nT = TypeVar('T')\r\nclass A(Generic[T]):\r\n\r\n def f(self) -> None:\r\n x: T\r\n```\r\n\r\nHowever in a static method this doesn't make sense, since we don't have an instance of `A` to provide any parameterized type for `T`:\r\n\r\n```python\r\nfrom typing import TypeVar, Generic\r\n\r\nT = TypeVar('T')\r\nclass A(Generic[T]):\r\n @staticmethod\r\n def f() -> None:\r\n x: T # Error we don't yet provide: Invalid type \"__main__.T\"\r\n```\r\n\r\nNor does this make any sense:\r\n\r\n```python\r\nfrom typing import TypeVar, Generic\r\n\r\nT = TypeVar('T')\r\nclass A(Generic[T]):\r\n @classmethod\r\n def f(cls) -> None:\r\n x: T # Error we don't yet provide: Invalid type \"__main__.T\"\r\n```\r\n\r\n","author":{"url":"https://github.com/sixolet","@type":"Person","name":"sixolet"},"datePublished":"2017-04-14T06:26:27Z","url":"https://github.com/python/mypy/issues/3172"}
| 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:642e7b03-c595-90d3-984a-8ac8551ba0bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8648:2148FB:29594B5:3867F87:6B004C8D |
| html-safe-nonce | 0b368ff867f2d4d62ace684071e871fd130cb3c43ae65f44e20b74e5832095f9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjQ4OjIxNDhGQjoyOTU5NEI1OjM4NjdGODc6NkIwMDRDOEQiLCJ2aXNpdG9yX2lkIjoiMzY4MjM5ODcwODE4OTY0NTk2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f114eba019ce721111ff4e3002dda41038beb0a998384246b6ab1f85dd44f67e |
| hovercard-subject-tag | issue:221750722 |
| 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/3172/issue_layout |
| twitter:image | https://opengraph.githubassets.com/38a3d3ce58ec1a019ccb7ecee922646c42c52021e66038ceb25c8b76be97a398/python/mypy/issues/3172 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/38a3d3ce58ec1a019ccb7ecee922646c42c52021e66038ceb25c8b76be97a398/python/mypy/issues/3172 |
| og:image:alt | Here's a type variable in a normal method. This works fine: from typing import TypeVar, Generic T = TypeVar('T') class A(Generic[T]): def f(self) -> None: x: T However in a static method this doesn... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sixolet |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width