Title: Type variables bounded by generic types cannot be used with `Type` · Issue #3148 · python/mypy · GitHub
Open Graph Title: Type variables bounded by generic types cannot be used with `Type` · Issue #3148 · python/mypy
X Title: Type variables bounded by generic types cannot be used with `Type` · Issue #3148 · python/mypy
Description: T = TypeVar('T') class X(Generic[T]): ... U = TypeVar('U', bound=X[T]) # Invalid type "test.T" def f(cls: Type[U]) -> U: # Unsupported type Type["U"] return cls() At first glance, this is a duplicate of #2756 . However, that issue is abo...
Open Graph Description: T = TypeVar('T') class X(Generic[T]): ... U = TypeVar('U', bound=X[T]) # Invalid type "test.T" def f(cls: Type[U]) -> U: # Unsupported type Type["U"] return cls() At first glance, this is a duplica...
X Description: T = TypeVar('T') class X(Generic[T]): ... U = TypeVar('U', bound=X[T]) # Invalid type "test.T" def f(cls: Type[U]) -> U: # Unsupported type Type["U"] return c...
Opengraph URL: https://github.com/python/mypy/issues/3148
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type variables bounded by generic types cannot be used with `Type`","articleBody":"```\r\nT = TypeVar('T')\r\nclass X(Generic[T]): ...\r\n\r\nU = TypeVar('U', bound=X[T]) # Invalid type \"test.T\"\r\ndef f(cls: Type[U]) -> U: # Unsupported type Type[\"U\"]\r\n return cls()\r\n```\r\n\r\nAt first glance, this is a duplicate of #2756 . However, that issue is about the first error message, and this issue is about the second.\r\n\r\nIn #2756 (as here), the \"Invalid type test.T\" message goes away once we provide a concrete parameter for `X`, like `U = TypeVar('U', bound=X[int])`. The `\"Unsupported type Type[\"U\"]` message, however, never goes away as long as `X` remains generic.\r\n\r\nI have a use case: `f` is supposed to convert some data into a `U`; the first argument is the class into which it is supposed to convert. The function uses some methods that are defined in `class X`, that's why I need to bound `U`.","author":{"url":"https://github.com/pkch","@type":"Person","name":"pkch"},"datePublished":"2017-04-09T07:46:54Z","url":"https://github.com/python/mypy/issues/3148"}
| 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:11db38f0-ba56-b3a6-8a49-afef6ea0d7c1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9ED0:2ACF58:413A55:5B3BE5:6B00707B |
| html-safe-nonce | 010ebed4b83543246ca29f248153efeb547cecde17fd847daf54fd844181d1b3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUQwOjJBQ0Y1ODo0MTNBNTU6NUIzQkU1OjZCMDA3MDdCIiwidmlzaXRvcl9pZCI6IjE5MTA3OTEwMzAwNjQ1NzQ1ODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f48c5f05ec1264af60803707e33b2c7247a783dfa489c570328566c8c5e71296 |
| hovercard-subject-tag | issue:220454809 |
| 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/3148/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20679b1f2653acaa6f47152a679d4ee8bf3a1d15aac6557d5626d759b63b6a84/python/mypy/issues/3148 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20679b1f2653acaa6f47152a679d4ee8bf3a1d15aac6557d5626d759b63b6a84/python/mypy/issues/3148 |
| og:image:alt | T = TypeVar('T') class X(Generic[T]): ... U = TypeVar('U', bound=X[T]) # Invalid type "test.T" def f(cls: Type[U]) -> U: # Unsupported type Type["U"] return cls() At first glance, this is a duplica... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkch |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width