René's URL Explorer Experiment


Title: Type mappings for generics · Issue #1273 · python/typing · GitHub

Open Graph Title: Type mappings for generics · Issue #1273 · python/typing

X Title: Type mappings for generics · Issue #1273 · python/typing

Description: (originally proposed here python/mypy#13870 , but it turns out this is a better place to discuss) Feature Assume we have a mapping between types, possibly because there's a method with many overloads that takes an object from the first c...

Open Graph Description: (originally proposed here python/mypy#13870 , but it turns out this is a better place to discuss) Feature Assume we have a mapping between types, possibly because there's a method with many overloa...

X Description: (originally proposed here python/mypy#13870 , but it turns out this is a better place to discuss) Feature Assume we have a mapping between types, possibly because there's a method with many ove...

Opengraph URL: https://github.com/python/typing/issues/1273

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type mappings for generics","articleBody":"(originally proposed here https://github.com/python/mypy/issues/13870 , but it turns out this is a better place to discuss)\r\n\r\n**Feature**\r\n\r\nAssume we have a mapping between types, possibly because there's a method with many overloads that takes an object from the first collection of types, and maps it into an object from the second collection of types.\r\n\r\nThen, assume we have a generic class for which we have a `TypeVar` that corresponds with the first type. Then there is a method in this generic that does the transformation and produces a corresponding type.\r\n\r\nRight now, it would be possible to type the outcome as a union, but much better would be to statically infer the output type.\r\n\r\n```python\r\nTypeLookupTable = TypeMapping('TypeLookupTable', {\r\n    FromType1: ToType1,\r\n    FromType2: ToType2,\r\n    FromType3: ToType3,\r\n    ...\r\n})\r\n\r\nT = TypeVar('T', bound=any_type_present_as_a_key_in_that_lookup_table)\r\n\r\n@dataclass\r\nclass SomeGeneric(Generic[T]):\r\n     data: T\r\n\r\n     def func(self) -> TypeLookupTable[T]:\r\n         # This function should produce an instance of the corresponding type of `T` in\r\n         # that lookup table.\r\n\r\n    def func2(self) -> ReturnTypeForFunctionCall[some_function, [T]]:\r\n        # This function returns an object for which the return type is\r\n        # inferred by looking at the overload of `some_function`\r\n        # when called  with input `T`.\r\n        return some_function(self.data)\r\n```\r\n\r\n**Pitch**\r\n\r\nI'm building a synchronous abstraction layer on top of an async library. This means every type from the async implementation will correspond to a type from the synchronous abstraction. There is one function `wrap` with tons of overloads that takes an async type and returns the corresponding sync type. (it also takes an `anyio.BlockingPortal`, but that's not relevant for this issue). There are many approaches for the implementation, the dictionary mapping being the easiest, because runtime introspection of the types in the dictionary is the easiest.\r\n\r\nRight now, I can't come up with other examples for situations where it's useful, but I'm sure there are other cases where a generic class calls any of a collection of function overloads and where we want to infer the corresponding return type.\r\n\r\nAmong the two demonstrated approaches, (`ReturnTypeForFunctionCall` and `TypeLookupTable`), I'm mostly in favor of `TypeLookupTable`, because a collection of overloads can always be expressed using that lookup table. Something like:\r\n\r\n```python\r\ndef function_with_many_overloads[T](data: T) -> TypeLookuptable[T]: ...\r\n```\r\n(That would expand to as many overloads as there are mapped types in that table.)\r\n\r\n\r\nFrom the mypy issue, I understand that this would be very useful for Numpy too.\r\nPossibly related thread: https://mail.python.org/archives/list/typing-sig@python.org/thread/VGBBY63CUV7LTBDIIXDPYK3OWTQTUN3Y/#KL3VLJDJM5WGLBXWUZHOZG5PMGY2MFWQ","author":{"url":"https://github.com/jonathanslenders","@type":"Person","name":"jonathanslenders"},"datePublished":"2022-10-15T19:36:01Z","url":"https://github.com/python/typing/issues/1273"}

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:a823178a-6564-cfc1-635a-c6e101bc93e9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA07E:308D9D:1F4F620:2A93AA5:6B0019CE
html-safe-nonce9995e6a64578b5e09a04101a9a9f32b793043513116a42587c50cb8fb2310299
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDdFOjMwOEQ5RDoxRjRGNjIwOjJBOTNBQTU6NkIwMDE5Q0UiLCJ2aXNpdG9yX2lkIjoiODExNjUwMDY3NTE3NDYwMzIxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfaf274b0dd50275f996c3967bfdf9a6f61f817269b5fb1ed6c49195ad2caa34c
hovercard-subject-tagissue:1410270631
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/typing/1273/issue_layout
twitter:imagehttps://opengraph.githubassets.com/026112745c16c0875fdd8812ca7277dfd67e02949c98f76ff11ef15c4bc62e03/python/typing/issues/1273
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/026112745c16c0875fdd8812ca7277dfd67e02949c98f76ff11ef15c4bc62e03/python/typing/issues/1273
og:image:alt(originally proposed here python/mypy#13870 , but it turns out this is a better place to discuss) Feature Assume we have a mapping between types, possibly because there's a method with many overloa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejonathanslenders
hostnamegithub.com
expected-hostnamegithub.com
Nonea2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4
turbo-cache-controlno-preview
go-importgithub.com/python/typing git https://github.com/python/typing.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id24604008
octolytics-dimension-repository_nwopython/typing
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24604008
octolytics-dimension-repository_network_root_nwopython/typing
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
release70121d4e855ee0bb7b75cf15d061d91f8863c0f8
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/1273#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F1273
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%2Ftyping%2Fissues%2F1273
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%2Ftyping
Reloadhttps://github.com/python/typing/issues/1273
Reloadhttps://github.com/python/typing/issues/1273
Reloadhttps://github.com/python/typing/issues/1273
pythonhttps://github.com/python
typinghttps://github.com/python/typing
Codehttps://github.com/python/typing
Issues206 (206)https://github.com/python/typing/issues
Pull requests27 (27)https://github.com/python/typing/pulls
Discussionshttps://github.com/python/typing/discussions
Actionshttps://github.com/python/typing/actions
Security and qualityhttps://github.com/python/typing/security
Insightshttps://github.com/python/typing/insights
https://github.com/python/typing
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/1273
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/1273
Type mappings for genericshttps://github.com/python/typing/issues/1273#top
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com/jonathanslenders
jonathanslendershttps://github.com/jonathanslenders
on Oct 15, 2022https://github.com/python/typing/issues/1273#issue-1410270631
python/mypy#13870https://github.com/python/mypy/issues/13870
https://mail.python.org/archives/list/typing-sig@python.org/thread/VGBBY63CUV7LTBDIIXDPYK3OWTQTUN3Y/#KL3VLJDJM5WGLBXWUZHOZG5PMGY2MFWQhttps://mail.python.org/archives/list/typing-sig@python.org/thread/VGBBY63CUV7LTBDIIXDPYK3OWTQTUN3Y/#KL3VLJDJM5WGLBXWUZHOZG5PMGY2MFWQ
jonathanslendershttps://github.com/jonathanslenders
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
on Oct 15, 2022https://github.com/python/typing/issues/1273#event-7595427290
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Oct 15, 2022https://github.com/python/typing/issues/1273#issuecomment-1279834743
https://github.com/betafcc
betafcchttps://github.com/betafcc
on Oct 16, 2022https://github.com/python/typing/issues/1273#issuecomment-1280034974
functools.singledispatchhttps://docs.python.org/3/library/functools.html#functools.singledispatch
@erictrauthttps://github.com/erictraut
https://github.com/jonathanslenders
jonathanslendershttps://github.com/jonathanslenders
on Oct 16, 2022https://github.com/python/typing/issues/1273#issuecomment-1280046476
@erictrauthttps://github.com/erictraut
@betafcchttps://github.com/betafcc
@erictrauthttps://github.com/erictraut
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Oct 16, 2022https://github.com/python/typing/issues/1273#issuecomment-1280056230
https://github.com/betafcc
betafcchttps://github.com/betafcc
on Oct 16, 2022https://github.com/python/typing/issues/1273#issuecomment-1280059574
@jonathanslendershttps://github.com/jonathanslenders
natural transformation of functors diagram put into wordshttps://en.wikipedia.org/wiki/Natural_transformation#/media/File:Natural_Transformation_between_two_functors.svg
fmaphttps://gist.github.com/betafcc/9b9317034e939a99cd32894952574843
one linershttps://hackage.haskell.org/package/base-4.17.0.0/docs/src/Data.Traversable.html#sequenceA
higher kinded typevarshttps://github.com/python/typing/issues/548
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Oct 17, 2022https://github.com/python/typing/issues/1273#issuecomment-1280200283
numpyhttps://github.com/BvB93/numpy/blob/8a0859835d3e6002858b9ffd9a232b059cf9ea6c/numpy/__init__.pyi#L2053
https://github.com/jonathanslenders
jonathanslendershttps://github.com/jonathanslenders
on Oct 26, 2022https://github.com/python/typing/issues/1273#issuecomment-1291719183
@betafcchttps://github.com/betafcc
@hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
https://github.com/randolf-scholz
randolf-scholzhttps://github.com/randolf-scholz
on Nov 4, 2022https://github.com/python/typing/issues/1273#issuecomment-1303273707
Mapped Typeshttps://www.typescriptlang.org/docs/handbook/2/mapped-types.html
https://github.com/matangover
matangoverhttps://github.com/matangover
on Dec 10, 2022https://github.com/python/typing/issues/1273#issuecomment-1345289689
Conditional Typeshttps://www.typescriptlang.org/docs/handbook/2/conditional-types.html
https://github.com/SimpleArt
SimpleArthttps://github.com/SimpleArt
on Feb 21, 2023https://github.com/python/typing/issues/1273#issuecomment-1438964766
https://github.com/SimpleArt
SimpleArthttps://github.com/SimpleArt
on Feb 21, 2023https://github.com/python/typing/issues/1273#issuecomment-1438972524
https://github.com/jonathanslenders
jonathanslendershttps://github.com/jonathanslenders
on Mar 13, 2023https://github.com/python/typing/issues/1273#issuecomment-1465958870
jonathanslendershttps://github.com/jonathanslenders
on Mar 13, 2023https://github.com/python/typing/issues/1273#event-8730526434
https://github.com/akpircher
akpircherhttps://github.com/akpircher
on Mar 16, 2023https://github.com/python/typing/issues/1273#issuecomment-1471184801
https://github.com/akpircher
akpircherhttps://github.com/akpircher
on Mar 16, 2023https://github.com/python/typing/issues/1273#issuecomment-1471246938
https://github.com/bwo
bwohttps://github.com/bwo
on Oct 1, 2023https://github.com/python/typing/issues/1273#issuecomment-1742168494
https://github.com/v--
v--https://github.com/v--
on Aug 21, 2024https://github.com/python/typing/issues/1273#issuecomment-2302562912
this commenthttps://github.com/python/mypy/issues/11501#issuecomment-973128934
numpy example abovehttps://github.com/python/typing/issues/1273#issuecomment-1280200283
https://private-user-images.githubusercontent.com/5711311/360006588-4245ed6e-3f05-4ea8-896a-8724bbd6fcd1.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUxNjkwMTksIm5iZiI6MTc5NTE2ODcxOSwicGF0aCI6Ii81NzExMzExLzM2MDAwNjU4OC00MjQ1ZWQ2ZS0zZjA1LTRlYTgtODk2YS04NzI0YmJkNmZjZDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MTEyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjExMjBUMDk1ODM5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTAwZWY4NTNiNDlmMGEzNzVhNDlhZGFmYWE5ZjMxNzE1ZTQ4NzYzYjE3ZWM2MDQ1YzQ0NGVkMmJhNTg3NWJmMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.QhSQfPe1nysIBkZr3DnVRiGgOamvGFHBhLwa7EV_-K0
https://github.com/plusls
pluslshttps://github.com/plusls
on Jan 17, 2025https://github.com/python/typing/issues/1273#issuecomment-2598556725
https://github.com/jstriebel
jstriebelhttps://github.com/jstriebel
on Oct 8, 2025https://github.com/python/typing/issues/1273#issuecomment-3379780581
#1273 (comment)https://github.com/python/typing/issues/1273#issuecomment-1280046476
#1273 (comment)https://github.com/python/typing/issues/1273#issuecomment-1280200283
#1273 (comment)https://github.com/python/typing/issues/1273#issuecomment-1280046476
https://github.com/jstriebel
jstriebelhttps://github.com/jstriebel
on Oct 8, 2025https://github.com/python/typing/issues/1273#issuecomment-3381128220
https://discuss.python.org/t/taking-the-argument-signature-from-a-different-function/42618/25https://discuss.python.org/t/taking-the-argument-signature-from-a-different-function/42618/25
Add a stdlib decorator that copies/applies the ParameterSpec from one function to another cpython#107001https://github.com/python/cpython/issues/107001
gh-107001: Add a stdlib decorator that copies/applies the ParameterSpec from one function to another cpython#121693https://github.com/python/cpython/pull/121693
https://github.com/juntyr
juntyrhttps://github.com/juntyr
on Oct 9, 2025https://github.com/python/typing/issues/1273#issuecomment-3386667863
https://github.com/BenjyWiener
BenjyWienerhttps://github.com/BenjyWiener
on Jan 4, 2026https://github.com/python/typing/issues/1273#issuecomment-3708093289
previewhttps://benjywiener-peps.readthedocs.io/en/overloaded-type/pep-9999/
sourcehttps://github.com/BenjyWiener/peps/blob/overloaded-type/peps/pep-9999.rst
this discourse threadhttps://discuss.python.org/t/typemap-generalizing-overload-semantics/105440
https://github.com/Avasam
Avasamhttps://github.com/Avasam
on Feb 2, 2026https://github.com/python/typing/issues/1273#issuecomment-3836709202
pypa/setuptools#5020https://github.com/pypa/setuptools/pull/5020
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/1273
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/1273
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%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.