Title: TypeVarTuple Transformations Before Unpack · Issue #1216 · python/typing · GitHub
Open Graph Title: TypeVarTuple Transformations Before Unpack · Issue #1216 · python/typing
X Title: TypeVarTuple Transformations Before Unpack · Issue #1216 · python/typing
Description: It would be useful to be able to apply type transformations to TypeVarTuple's types. Some motivating examples: Ts = TypeVarTuple('Ts') class Example(Generic[*Ts]): def __init__(self, *types: *type[Ts]) -> None: self.types = types def cre...
Open Graph Description: It would be useful to be able to apply type transformations to TypeVarTuple's types. Some motivating examples: Ts = TypeVarTuple('Ts') class Example(Generic[*Ts]): def __init__(self, *types: *type[...
X Description: It would be useful to be able to apply type transformations to TypeVarTuple's types. Some motivating examples: Ts = TypeVarTuple('Ts') class Example(Generic[*Ts]): def __init__(self, *t...
Opengraph URL: https://github.com/python/typing/issues/1216
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeVarTuple Transformations Before Unpack","articleBody":"It would be useful to be able to apply type transformations to `TypeVarTuple`'s types. Some motivating examples:\r\n\r\n```python\r\n Ts = TypeVarTuple('Ts')\r\n\r\n class Example(Generic[*Ts]):\r\n def __init__(self, *types: *type[Ts]) -> None:\r\n self.types = types\r\n\r\n def create_defaults(self) -> tuple[*Ts]:\r\n return tuple(t() for t in self.types)\r\n\r\n def create_lists(self) -> tuple[*list[Ts]]:\r\n return tuple([t()] for t in self.types)\r\n\r\n def create_callables(self) -> tuple[*Callable[[], Ts]]:\r\n return tuple(lambda: t() for t in self.types)\r\n\r\n e = Example(int, str)\r\n\r\n assert_type(e.create_defaults(), tuple[int, str])\r\n assert_type(e.create_lists(), tuple[list[int], list[str]])\r\n assert_type(e.create_callables(), tuple[Callable[[], int], Callable[[], str]])\r\n```\r\nAt a high level, everything between the `*` and the `TypeVarTuple` it expands would be applied per type in the tuple before it's unpacked.\r\n\r\nThere are some decisions to be made about how the expansion is done if there are multiple `TypeVarTuple`s in the expand expression, but I think it can be supported and I think the intuitive thing would be to zip up all the `TypeVarTuple`s. For example,\r\n`tuple[*tuple[Ts, Us]]` with `Ts = (int, str)` and `Us = (float, bytes)` would be `tuple[tuple[int, float], tuple[str, bytes]]`, with the implementation enforcing equal-length `TypeVarTuple`s.\r\n\r\nIf there's a workaround for this using the existing logic, let me know. My current use case involves keeping a reference to the runtime types, so `*type[Ts]` is what I'm looking for at the moment.","author":{"url":"https://github.com/llchan","@type":"Person","name":"llchan"},"datePublished":"2022-06-24T21:18:23Z","url":"https://github.com/python/typing/issues/1216"}
| 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:3982be12-a094-10bc-29af-1c73943fb1ff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA6C:2D8191:458C9:5C0F5:6B001A6A |
| html-safe-nonce | 6f92ebe3bce5e68d4ab979b587b78165ffe07a9076e76914d357900d4cb97ef2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTZDOjJEODE5MTo0NThDOTo1QzBGNTo2QjAwMUE2QSIsInZpc2l0b3JfaWQiOiIxNDM3NzQ2MzY4NjI0OTkwODI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d1fcc20cbd093d327a342276659a67bda6b93c490780111ddfd5ee5548ed8b7d |
| hovercard-subject-tag | issue:1284201833 |
| 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/1216/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68082f5fc15a55c24907bc75d3bbac73eef2e7f840164655a2ab185d8325568a/python/typing/issues/1216 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68082f5fc15a55c24907bc75d3bbac73eef2e7f840164655a2ab185d8325568a/python/typing/issues/1216 |
| og:image:alt | It would be useful to be able to apply type transformations to TypeVarTuple's types. Some motivating examples: Ts = TypeVarTuple('Ts') class Example(Generic[*Ts]): def __init__(self, *types: *type[... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | llchan |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width