René's URL Explorer Experiment


Title: Consider making `Template` and `Interpolation` generic at runtime · Issue #133970 · python/cpython · GitHub

Open Graph Title: Consider making `Template` and `Interpolation` generic at runtime · Issue #133970 · python/cpython

X Title: Consider making `Template` and `Interpolation` generic at runtime · Issue #133970 · python/cpython

Description: Feature or enhancement Template and Interpolation will once be supported by type-checkers. And it might be worth adding generics support for these types. Example from string.templatelib import Template, Interpolation from urllib.parse im...

Open Graph Description: Feature or enhancement Template and Interpolation will once be supported by type-checkers. And it might be worth adding generics support for these types. Example from string.templatelib import Temp...

X Description: Feature or enhancement Template and Interpolation will once be supported by type-checkers. And it might be worth adding generics support for these types. Example from string.templatelib import Temp...

Opengraph URL: https://github.com/python/cpython/issues/133970

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider making `Template` and `Interpolation` generic at runtime","articleBody":"# Feature or enhancement\n\n`Template` and `Interpolation` will once be supported by type-checkers. And it might be worth adding generics support for these types. \n\n## Example\n\n```python\nfrom string.templatelib import Template, Interpolation\nfrom urllib.parse import quote_plus\n\ndomain = 'example.com'\nquery = 'python string formatting is too complex'\ntemplate = t'https://{domain}?q={query}'\n\ndef quote_url(interp: Interpolation[str]) -> str:\n    return quote_plus(interp.value)\n\ndef format_url(template: Template) -> str:\n    parts = []\n    for part in template:\n        match part:\n            case str() as s:  # regular string\n                parts.append(s)\n            case Interpolation(str(), expression='query') as interp:\n                parts.append(quote_url(interp))\n            case Interpolation(value):\n                parts.append(value)\n    return ''.join(parts)\n\nprint(format_url(template))\n```\n\nHere we can see that `Interpolation[str]` can be useful in users' code.\n\nWe can also benefit from generic `Template`, where we can make it generic based on exact `TypeVarTuple`. Demo:\n\n```python\nfrom typing import Any, TypeVarTuple, Generic, Unpack\n\nTs = TypeVarTuple('Ts', default=Unpack[tuple[Any, ...]])\n\nclass Template(Generic[*Ts]):\n    def __new__(cls, *args: *Ts) -> Template[*Ts]: ...  # type: ignore[empty-body]\n    \nclass Interpolation: ...\n    \nreveal_type(Template('a', 'b', Interpolation(), 'd'))\n# Revealed type is \"__main__.Template[Literal['a']?, Literal['b']?, __main__.Interpolation, Literal['d']?]\"\n```\n\nhttps://mypy-play.net/?mypy=latest&python=3.13&gist=0dc13b3b926e1efb9783ab9b70d39ceb\n\nThis can potentially help type checkers to infer correct `Template` type.\n\n## Current state\n\nCurrent `typeshed` definitions: https://github.com/python/typeshed/blob/main/stdlib/string/templatelib.pyi\n\nHere's how `Template` is defined:\n\n```python\n@final\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 | str) -> Template: ...\n    @property\n    def values(self) -> tuple[Any, ...]: ...  # Tuple of interpolation values, which can have any type\n```\nIdeally, it should be generic on `TypeVarTuple`\n\nHere's how `Interpolation` is defined:\n\n```python\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```\n\nIdeally, it should be generic on `value`. `Interpolation[str]` means that `value` is `str` and `Interpolation[tuple[int, int]]` means that `Interpolation` has a `value` for type `tuple[int, int]`\n\n## Proposal\n\nFrom runtime's part with only need to add `Py_GenericAlias`, that's it.\n\nIs it too late for feature freeze? This is a minor detail, so I hope it is not :)\n\nI have a PR ready.\n\nCC @srittau @JelleZijlstra @lysnikolaou \n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-133976\n* gh-134029\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2025-05-13T13:15:18Z","url":"https://github.com/python/cpython/issues/133970"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b5e45b29-feb2-f48b-9e30-d2a772dd7cb4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9060:B1603:368EF7F:488EB0D:6B0049FB
html-safe-nonce1f98cf53e197000192d84c4b51350cffb49f8f9a098cd9114565f0aa2cd39d83
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDYwOkIxNjAzOjM2OEVGN0Y6NDg4RUIwRDo2QjAwNDlGQiIsInZpc2l0b3JfaWQiOiIxODg0NzU2MDcyMTg3NTc4ODc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac290a0f0cb7802fc8cd27876db9749581a39e47411f3a472d4552df656057d9da
hovercard-subject-tagissue:3060050306
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/133970/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7724a63e476fa36eda59d017eda67c6c32dc30ae58cf5b535c0b1749fffa4b80/python/cpython/issues/133970
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7724a63e476fa36eda59d017eda67c6c32dc30ae58cf5b535c0b1749fffa4b80/python/cpython/issues/133970
og:image:altFeature or enhancement Template and Interpolation will once be supported by type-checkers. And it might be worth adding generics support for these types. Example from string.templatelib import Temp...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesobolevn
hostnamegithub.com
expected-hostnamegithub.com
Nonef9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb27c5dde30676028abd5c5fc53ce5c9b625f8281
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/133970#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F133970
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F133970
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/133970
Reloadhttps://github.com/python/cpython/issues/133970
Reloadhttps://github.com/python/cpython/issues/133970
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/133970
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/133970
Consider making Template and Interpolation generic at runtimehttps://github.com/python/cpython/issues/133970#top
https://github.com/sobolevn
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
triagedThe issue has been accepted as valid by a triager.https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22triaged%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#issue-3060050306
https://mypy-play.net/?mypy=latest&python=3.13&gist=0dc13b3b926e1efb9783ab9b70d39cebhttps://mypy-play.net/?mypy=latest&python=3.13&gist=0dc13b3b926e1efb9783ab9b70d39ceb
https://github.com/python/typeshed/blob/main/stdlib/string/templatelib.pyihttps://github.com/python/typeshed/blob/main/stdlib/string/templatelib.pyi
@srittauhttps://github.com/srittau
@JelleZijlstrahttps://github.com/JelleZijlstra
@lysnikolaouhttps://github.com/lysnikolaou
gh-133970: Make PEP750 types generic #133976https://github.com/python/cpython/pull/133976
[3.14] gh-133970: Make PEP750 types generic (GH-133976) #134029https://github.com/python/cpython/pull/134029
Nexthttps://github.com/python/cpython/issues/133970?timeline_page=1
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#event-17635453505
sobolevnhttps://github.com/sobolevn
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
on May 13, 2025https://github.com/python/cpython/issues/133970#event-17635453905
https://github.com/srittau
srittauhttps://github.com/srittau
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2876540697
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2876562429
@srittauhttps://github.com/srittau
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2876912575
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2877040940
@JelleZijlstrahttps://github.com/JelleZijlstra
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#event-17638461027
pythongh-133970: Make PEP750 types generichttps://github.com/sobolevn/cpython/commit/531516888522b50f8c01dbeeb573a11f3abed67d
pythongh-133970https://github.com/python/cpython/issues/133970
5315168https://github.com/sobolevn/cpython/commit/531516888522b50f8c01dbeeb573a11f3abed67d
https://github.com/AA-Turner
AA-Turnerhttps://github.com/AA-Turner
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2878088406
@lysnikolaouhttps://github.com/lysnikolaou
@davepeckhttps://github.com/davepeck
https://github.com/AA-Turner
AA-Turnerhttps://github.com/AA-Turner
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2878101750
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2878110630
@AA-Turnerhttps://github.com/AA-Turner
https://github.com/davepeck
davepeckhttps://github.com/davepeck
on May 14, 2025https://github.com/python/cpython/issues/133970#issuecomment-2878456800
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 14, 2025https://github.com/python/cpython/issues/133970#issuecomment-2878460328
https://github.com/TeamSpen210
TeamSpen210https://github.com/TeamSpen210
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2881894877
sobolevnhttps://github.com/sobolevn
on May 15, 2025https://github.com/python/cpython/issues/133970#event-17665332167
gh-133970: Make PEP750 types generic (#133976)https://github.com/python/cpython/commit/c3a1da5b9397867e6b3169dd17cb33ef2898da4a
gh-133970https://github.com/python/cpython/issues/133970
#133976https://github.com/python/cpython/pull/133976
c3a1da5https://github.com/python/cpython/commit/c3a1da5b9397867e6b3169dd17cb33ef2898da4a
miss-islingtonhttps://github.com/miss-islington
on May 15, 2025https://github.com/python/cpython/issues/133970#event-17665335239
pythongh-133970: Make PEP750 types generic (pythonGH-133976)https://github.com/miss-islington/cpython/commit/bd2d2291d86eca9545b5402f34ff2a4ec6d924fd
pythongh-133970https://github.com/python/cpython/issues/133970
pythonGH-133976https://github.com/python/cpython/pull/133976
bd2d229https://github.com/miss-islington/cpython/commit/bd2d2291d86eca9545b5402f34ff2a4ec6d924fd
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2882709323
sobolevnhttps://github.com/sobolevn
on May 15, 2025https://github.com/python/cpython/issues/133970#event-17665668200
[3.14] gh-133970: Make PEP750 types generic (GH-133976) (#134029)https://github.com/python/cpython/commit/f2a4b1066be66574a147bc353efc91a6dc65753d
gh-133970https://github.com/python/cpython/issues/133970
GH-133976https://github.com/python/cpython/pull/133976
#134029https://github.com/python/cpython/pull/134029
f2a4b10https://github.com/python/cpython/commit/f2a4b1066be66574a147bc353efc91a6dc65753d
https://github.com/lysnikolaou
lysnikolaouhttps://github.com/lysnikolaou
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2884201425
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2884309593
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2884375739
https://github.com/lysnikolaou
lysnikolaouhttps://github.com/lysnikolaou
on May 15, 2025https://github.com/python/cpython/issues/133970#issuecomment-2884833113
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Jun 11, 2025https://github.com/python/cpython/issues/133970#issuecomment-2963044853
examplehttps://pyright-play.net/?pythonVersion=3.14&code=FAOwhgtgpgBAvDARAdQPYCcA2ATRwAu8SAElJpqojPogN7jQC%2BeQA
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Jun 12, 2025https://github.com/python/cpython/issues/133970#issuecomment-2964966254
python/steering-council#289https://github.com/python/steering-council/issues/289
picnixzhttps://github.com/picnixz
triagedThe issue has been accepted as valid by a triager.https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22triaged%22
on Jun 13, 2025https://github.com/python/cpython/issues/133970#event-18137965459
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Jun 13, 2025https://github.com/python/cpython/issues/133970#issuecomment-2971012657
Pranjal095https://github.com/Pranjal095
on Jul 12, 2025https://github.com/python/cpython/issues/133970#event-18600172982
pythongh-133970: Make PEP750 types generic (python#133976)https://github.com/Pranjal095/cpython/commit/cbfef5116192f5ba6117480f042acdeff42a9c72
pythongh-133970https://github.com/python/cpython/issues/133970
python#133976https://github.com/python/cpython/pull/133976
cbfef51https://github.com/Pranjal095/cpython/commit/cbfef5116192f5ba6117480f042acdeff42a9c72
taegyunkimhttps://github.com/taegyunkim
on Aug 4, 2025https://github.com/python/cpython/issues/133970#event-18976815796
pythongh-133970: Make PEP750 types generic (python#133976)https://github.com/taegyunkim/cpython/commit/96a184c3a0ab502995e9aa86215a4c40d07c14cd
pythongh-133970https://github.com/python/cpython/issues/133970
python#133976https://github.com/python/cpython/pull/133976
96a184chttps://github.com/taegyunkim/cpython/commit/96a184c3a0ab502995e9aa86215a4c40d07c14cd
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/133970
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/133970
sobolevnhttps://github.com/sobolevn
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
triagedThe issue has been accepted as valid by a triager.https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22triaged%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.