Title: (3.14) Templates not typeable without TypeVarTuple transformations · Issue #14878 · python/typeshed · GitHub
Open Graph Title: (3.14) Templates not typeable without TypeVarTuple transformations · Issue #14878 · python/typeshed
X Title: (3.14) Templates not typeable without TypeVarTuple transformations · Issue #14878 · python/typeshed
Description: I recently tried to create my own stubs for Python 3.14's Template and Interpolation types, but it seems that is currently not possible. I waited a while and searched a lot and did not find anybody talk about this issue anywhere. Their r...
Open Graph Description: I recently tried to create my own stubs for Python 3.14's Template and Interpolation types, but it seems that is currently not possible. I waited a while and searched a lot and did not find anybody...
X Description: I recently tried to create my own stubs for Python 3.14's Template and Interpolation types, but it seems that is currently not possible. I waited a while and searched a lot and did not find any...
Opengraph URL: https://github.com/python/typeshed/issues/14878
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"(3.14) Templates not typeable without TypeVarTuple transformations","articleBody":"I recently tried to create my own stubs for Python 3.14's `Template` and `Interpolation` types, but it seems that is currently not possible. I waited a while and searched a lot and did not find anybody talk about this issue anywhere.\n\nTheir runtime generic-ness was recently added:\nhttps://github.com/python/cpython/issues/133970\n\nBut it seems that it is not currently possible to actually type hint them correctly within the current typing spec, because transformations of the `TypeVarTuple` would be necessary. (https://github.com/python/typing/issues/1216)\n\nCurrently the code for those two classes' typing stubs looks like this:\n```py\nclass Template: # TODO: consider making `Template` generic on `TypeVarTuple`\n strings: tuple[str, ...]\n interpolations: tuple[Interpolation, ...]\n\n def __new__(cls, *args: str | Interpolation) -> Template: ...\n def __iter__(self) -> Iterator[str | Interpolation]: ...\n def __add__(self, other: Template, /) -> Template: ...\n def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...\n @property\n def values(self) -> tuple[Any, ...]: ... # Tuple of interpolation values, which can have any type\n\n@final\nclass Interpolation:\n value: Any # TODO: consider making `Interpolation` generic in runtime\n expression: str\n conversion: Literal[\"a\", \"r\", \"s\"] | None\n format_spec: str\n\n __match_args__ = (\"value\", \"expression\", \"conversion\", \"format_spec\")\n\n def __new__(\n cls, value: Any, expression: str = \"\", conversion: Literal[\"a\", \"r\", \"s\"] | None = None, format_spec: str = \"\"\n ) -> Interpolation: ...\n def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...\n```\n\nAnd it would need to be updated to something like this (using newer syntax for this example):\n```py\nfrom types import GenericAlias\nfrom typing import Any, final, Iterator, Literal\n\nclass Template[*Ts]:\n strings: tuple[str, ...]\n interpolations: tuple[Interpolation[Ts], ...] # Not possible to map/transform onto interpolations\n\n def __new__(cls, *args: str | Interpolation[Ts]) -> Template: ... # Not possible to map/transform onto interpolations\n def __iter__(self) -> Iterator[str | Interpolation[Ts]]: ... # Not possible to map/transform onto interpolations\n def __add__[*OtherTs](self, other: Template[*OtherTs], /) -> Template[*Ts, *OtherTs]: ...\n def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...\n @property\n def values(self) -> tuple[*Ts]: ...\n\n@final\nclass Interpolation[T]:\n value: T\n expression: str\n conversion: Literal[\"a\", \"r\", \"s\"] | None\n format_spec: str\n\n __match_args__ = (\"value\", \"expression\", \"conversion\", \"format_spec\")\n\n def __new__(\n cls, value: T, expression: str = \"\", conversion: Literal[\"a\", \"r\", \"s\"] | None = None, format_spec: str = \"\"\n ) -> Interpolation[T]: ...\n def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...\n```\nSo basically we would need to map the `TypeVarTuple`'s elements into each `Interpolation`, which is currently not possible.\n\nSo it looks like typing `Templates` and `Interpolations` is not possible until transformations get added. If I missed something or there is a workaround, please inform me! Thank you! 👍 ","author":{"url":"https://github.com/JoniKauf","@type":"Person","name":"JoniKauf"},"datePublished":"2025-10-15T09:50:19Z","url":"https://github.com/python/typeshed/issues/14878"}
| 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:39a69e04-7620-aace-ebf2-dacf7db6d466 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAB8:184B81:361DEDE:47FCB45:6B004C4A |
| html-safe-nonce | a00e2350576ac1ea773c5b2d38f3970e2ebab28d957020d5cc2a8f46c292c270 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUI4OjE4NEI4MTozNjFERURFOjQ3RkNCNDU6NkIwMDRDNEEiLCJ2aXNpdG9yX2lkIjoiNDI4Njc0ODM3ODYzNDg0NDkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e36b51ff6157628e415c839dcdfaa1a2ad6455f884d816722cb93baaaee6dfed |
| hovercard-subject-tag | issue:3517247242 |
| 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/typeshed/14878/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80da4a7a3674f11308103ce1c5c5a188b5639eac2dde3e9ac2d18e39f9002bdb/python/typeshed/issues/14878 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80da4a7a3674f11308103ce1c5c5a188b5639eac2dde3e9ac2d18e39f9002bdb/python/typeshed/issues/14878 |
| og:image:alt | I recently tried to create my own stubs for Python 3.14's Template and Interpolation types, but it seems that is currently not possible. I waited a while and searched a lot and did not find anybody... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JoniKauf |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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