Title: Can we have a generic Type[C]? · Issue #107 · python/typing · GitHub
Open Graph Title: Can we have a generic Type[C]? · Issue #107 · python/typing
X Title: Can we have a generic Type[C]? · Issue #107 · python/typing
Description: The type object occupies a rather strange place in the type hierarchy: >>> type(type) is type True (I'm pretty sure that's a flat lie, since you can't instantiate something from itself, but regardless...) >>> isinstance(type, object) Tru...
Open Graph Description: The type object occupies a rather strange place in the type hierarchy: >>> type(type) is type True (I'm pretty sure that's a flat lie, since you can't instantiate something from itself, but regardl...
X Description: The type object occupies a rather strange place in the type hierarchy: >>> type(type) is type True (I'm pretty sure that's a flat lie, since you can't instantiate something fro...
Opengraph URL: https://github.com/python/typing/issues/107
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can we have a generic Type[C]?","articleBody":"The `type` object occupies a rather strange place in the type hierarchy:\n\n```\n>>> type(type) is type\nTrue\n```\n\n(I'm pretty sure that's a flat lie, since you can't instantiate something from itself, but regardless...)\n\n```\n>>> isinstance(type, object)\nTrue\n>>> isinstance(object, type)\nTrue\n>>> isinstance(type, type)\nTrue\n```\n\nIn Java, the (very rough) equivalent is a class, specifically [`Class\u003cT>`](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html). It's also generic; the type variable refers to the instance. Java has it easy because they don't support metaclasses. Classes are not first class in Java, so their type hierarchy doesn't have to deal with the strange loops shown above.\n\nI realize metaclasses in their full generality are out of scope (at least for now), but a generic `Type[T]` like Java's would be nice to have. So far as I can tell from the Mypy documentation, it doesn't currently exist.\n\nHere's some example code which might like to have this feature:\n\n```\ndef make_foo(class_: Type[T]) -> T:\n # Instantiate and return a T\n```\n","author":{"url":"https://github.com/NYKevin","@type":"Person","name":"NYKevin"},"datePublished":"2015-05-08T21:42:19Z","url":"https://github.com/python/typing/issues/107"}
| 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:0a43bb72-44f6-5631-2c14-53695b2a7235 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA88:3AE712:DBF6A8:12755A4:6B005652 |
| html-safe-nonce | fcbea7aa24b31d7f938c23255432de8e43bfeebf1a83922db1ce95040b0c4d54 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTg4OjNBRTcxMjpEQkY2QTg6MTI3NTVBNDo2QjAwNTY1MiIsInZpc2l0b3JfaWQiOiI4OTg1ODc3NDc5ODA1NzAzNzYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 54c849baa859b0237bc28e088a27bb3e5ef25fe54a0afcc2f9ed23e8dd5c8679 |
| hovercard-subject-tag | issue:74505744 |
| 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/typing/107/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c628af29615b7d4a9a355701f5bd0b8e6e0b3065a9168251cd1da79444b96817/python/typing/issues/107 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c628af29615b7d4a9a355701f5bd0b8e6e0b3065a9168251cd1da79444b96817/python/typing/issues/107 |
| og:image:alt | The type object occupies a rather strange place in the type hierarchy: >>> type(type) is type True (I'm pretty sure that's a flat lie, since you can't instantiate something from itself, but regardl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NYKevin |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width