René's URL Explorer Experiment


Title: Integer generics · Issue #3345 · python/mypy · GitHub

Open Graph Title: Integer generics · Issue #3345 · python/mypy

X Title: Integer generics · Issue #3345 · python/mypy

Description: Dependent types have been brought up before in a few places: #366, this python-ideas thread, and most recently, #3062. The latter limits itself to one specific feature of a dependent type system, namely, support for simple literal types....

Open Graph Description: Dependent types have been brought up before in a few places: #366, this python-ideas thread, and most recently, #3062. The latter limits itself to one specific feature of a dependent type system, n...

X Description: Dependent types have been brought up before in a few places: #366, this python-ideas thread, and most recently, #3062. The latter limits itself to one specific feature of a dependent type system, n...

Opengraph URL: https://github.com/python/mypy/issues/3345

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Integer generics","articleBody":"Dependent types have been brought up before in a few places: #366, [this python-ideas thread](https://mail.python.org/pipermail/python-ideas/2014-August/028853.html), and most recently, #3062. The latter limits itself to one specific feature of a dependent type system, namely, support for simple literal types.\r\n\r\nAnother limited feature which could prove helpful is support for _integer generics_ —that is, the ability to parametrize types by integers as well as other types. For example, the length of a homogeneous tuple could be parametrized:\r\n\r\n```python\r\n# Currently supported:\r\nTuple[int, int, int] # A tuple of 3 ints\r\nTuple[int, ...] # A tuple of any number of ints\r\n\r\n# Proposed:\r\nTuple[int, 256] # A tuple of 256 ints\r\n```\r\n\r\nOne real-world use-case for this came up in python/typing#221:\r\n```python\r\n# Currently supported:\r\nSboxType = Tuple[\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n    Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int],\r\n]\r\n\r\n# Proposed:\r\nSboxType = Tuple[Tuple[int, 16], 8] # A tuple of 8 tuples of 16 ints each\r\n```\r\n\r\nInteger genericity could also be used for things like statically checking vector or matrix dimensions:\r\n```python\r\nN = TypeVar('N', numeric=True) # one idea for denoting type-level integers\r\n\r\nclass Vector(Generic[N]):\r\n    def __init__(self, values: Iterable[float, N]) -> None:\r\n        self.value = tuple(values)\r\n\r\n    def __add__(self, other: Vector[N]) -> Vector[N]:\r\n        return Vector(a + b for a, b in zip(self.values, other.values))\r\n\r\n# ...more code...\r\n\r\ndef matmul(a: Matrix[N, M], b: Matrix[M, D]) -> Matrix[N, D]: ...\r\n```\r\n\r\nNote that the Rust community has been discussing this for some time (as well as the more general _const generics_) and has a lot of material collected on the motivation, challenges, and details of such a feature:\r\n* [Pre-RFC: Integer Templating](https://internals.rust-lang.org/t/pre-rfc-integer-templating/2974)\r\n* rust-lang/rfcs#1038: Parameterize types over numerics / type level integers\r\n* rust-lang/rfcs#1931: RFC: Constant generics (restricted Π types) for Rust, core RFC (v2)\r\n* [[lang-team-minutes] Const generics](https://internals.rust-lang.org/t/lang-team-minutes-const-generics/5090)\r\n\r\nWhether or not it's a good fit for Python is an open question, of course, but I figured I should at least bring it up for discussion! (Especially since it could interact with #3062 in interesting ways.)\r\n\r\n---\r\n\r\n_(Even nicer would be to support simple type-level expressions so we could do things like this..._\r\n```python\r\n# Vector concatenation (relevant: http://stackoverflow.com/q/43292197/1974654)\r\ndef concat(a: Vector[N], b: Vector[M]) -> Vector[N+M]: ...\r\n\r\n# The `zip` builtin (based on the typeshed stub)\r\n@overload\r\ndef zip(iter1: Iterable[_T1, N1],\r\n        iter2: Iterable[_T2, N2]) -> Iterator[Tuple[_T1, _T2], min(N1, N2)]: ...\r\n\r\n# HDL-like bit vector operations\r\ndef add(a: BitVec[N], b: BitVec[M]) -> BitVec[max(N, M) + 1]: ...\r\n```\r\n_...but that may be taking it too far. To avoid running arbitrary user code the expression language would have to be explicitly defined and simple enough to implement in languages other than Python; it may be feasible to support something like +, -, *, //, %, **, max(), min(), and abs(), though.)_","author":{"url":"https://github.com/msegado","@type":"Person","name":"msegado"},"datePublished":"2017-05-09T19:41:19Z","url":"https://github.com/python/mypy/issues/3345"}

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:5bd35a47-c0ae-cef5-f97f-b8ff2a98032a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD962:1FBEEF:140F490:1A27E54:6B000686
html-safe-nonce3a03d9edf1d2e3a7f4f8ae95cbd1cec67416c3fe12790b8b7b077410ecc9c2e2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTYyOjFGQkVFRjoxNDBGNDkwOjFBMjdFNTQ6NkIwMDA2ODYiLCJ2aXNpdG9yX2lkIjoiNjA5MjUzMTg3NzA2MTU5MjcxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac47ef2cee7f6ac0c3506e24da77c7dd303aaffdc6a3dfd8236154bb2b587b6c01
hovercard-subject-tagissue:227475500
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/mypy/3345/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b590726c6cf2c2356209f47b1d1c50c991d5b11245cc3fdf9664be656afa15ee/python/mypy/issues/3345
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b590726c6cf2c2356209f47b1d1c50c991d5b11245cc3fdf9664be656afa15ee/python/mypy/issues/3345
og:image:altDependent types have been brought up before in a few places: #366, this python-ideas thread, and most recently, #3062. The latter limits itself to one specific feature of a dependent type system, n...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemsegado
hostnamegithub.com
expected-hostnamegithub.com
None0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
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
release16a11879678aaf97e2a42c33ee70830aa084fa37
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/3345#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F3345
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%2Fmypy%2Fissues%2F3345
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%2Fmypy
Reloadhttps://github.com/python/mypy/issues/3345
Reloadhttps://github.com/python/mypy/issues/3345
Reloadhttps://github.com/python/mypy/issues/3345
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests547 (547)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/3345
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/3345
Integer genericshttps://github.com/python/mypy/issues/3345#top
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
https://github.com/msegado
msegadohttps://github.com/msegado
on May 9, 2017https://github.com/python/mypy/issues/3345#issue-227475500
#366https://github.com/python/mypy/issues/366
this python-ideas threadhttps://mail.python.org/pipermail/python-ideas/2014-August/028853.html
#3062https://github.com/python/mypy/issues/3062
python/typing#221https://github.com/python/typing/issues/221
Pre-RFC: Integer Templatinghttps://internals.rust-lang.org/t/pre-rfc-integer-templating/2974
Parameterize types over numerics / type level integers rust-lang/rfcs#1038https://github.com/rust-lang/rfcs/issues/1038
RFC: Constant generics (restricted Π types) for Rust, core RFC (v2) rust-lang/rfcs#1931https://github.com/rust-lang/rfcs/pull/1931
[lang-team-minutes] Const genericshttps://internals.rust-lang.org/t/lang-team-minutes-const-generics/5090
#3062https://github.com/python/mypy/issues/3062
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on May 10, 2017https://github.com/python/mypy/issues/3345#issuecomment-300435069
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on May 10, 2017https://github.com/python/mypy/issues/3345#issuecomment-300474141
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on May 10, 2017https://github.com/python/mypy/issues/3345#issuecomment-300615522
ilevkivskyihttps://github.com/ilevkivskyi
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
on May 19, 2017https://github.com/python/mypy/issues/3345#event-1090253348
https://github.com/PaperclipBadger
PaperclipBadgerhttps://github.com/PaperclipBadger
on Aug 29, 2017https://github.com/python/mypy/issues/3345#issuecomment-325676694
https://github.com/saulshanabrook
saulshanabrookhttps://github.com/saulshanabrook
on Jul 2, 2018https://github.com/python/mypy/issues/3345#issuecomment-401799046
playing withhttps://github.com/saulshanabrook/moa
https://github.com/saulshanabrook
saulshanabrookhttps://github.com/saulshanabrook
on Jul 2, 2018https://github.com/python/mypy/issues/3345#issuecomment-401804487
generic protocolshttps://mypy.readthedocs.io/en/latest/generics.html#generic-protocols
Relay projecthttps://dl.acm.org/citation.cfm?id=3211348
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Jul 2, 2018https://github.com/python/mypy/issues/3345#issuecomment-401893683
https://github.com/saulshanabrook
saulshanabrookhttps://github.com/saulshanabrook
on Jul 2, 2018https://github.com/python/mypy/issues/3345#issuecomment-401894999
https://github.com/msegado
msegadohttps://github.com/msegado
on Jul 3, 2018https://github.com/python/mypy/issues/3345#issuecomment-402228665
https://github.com/leonardo-m
leonardo-mhttps://github.com/leonardo-m
on Jul 30, 2018https://github.com/python/mypy/issues/3345#issuecomment-409024434
rust-lang/rfcs#2000https://github.com/rust-lang/rfcs/pull/2000
rust-lang/rust#76560https://github.com/rust-lang/rust/issues/76560
https://github.com/graue70
graue70https://github.com/graue70
on May 5, 2020https://github.com/python/mypy/issues/3345#issuecomment-624142993
https://github.com/fylux
fyluxhttps://github.com/fylux
on Sep 11, 2020https://github.com/python/mypy/issues/3345#issuecomment-691144273
linkhttps://mail.python.org/archives/list/typing-sig@python.org/thread/JKYLI2IK42LIU26YXBW3N2TE2YQN4ESQ/
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Sep 11, 2020https://github.com/python/mypy/issues/3345#issuecomment-691185284
linkhttps://mail.python.org/archives/list/typing-sig@python.org/thread/JKYLI2IK42LIU26YXBW3N2TE2YQN4ESQ/
https://github.com/leonardo-m
leonardo-mhttps://github.com/leonardo-m
on Sep 11, 2020https://github.com/python/mypy/issues/3345#issuecomment-691219513
https://futhark-lang.org/blog/2020-03-15-futhark-0.15.1-released.htmlhttps://futhark-lang.org/blog/2020-03-15-futhark-0.15.1-released.html
https://github.com/luphord
luphordhttps://github.com/luphord
on Nov 25, 2020https://github.com/python/mypy/issues/3345#issuecomment-733859208
linkhttps://mail.python.org/archives/list/typing-sig@python.org/thread/JKYLI2IK42LIU26YXBW3N2TE2YQN4ESQ/
@fyluxhttps://github.com/fylux
https://github.com/fylux
fyluxhttps://github.com/fylux
on Nov 25, 2020https://github.com/python/mypy/issues/3345#issuecomment-733941393
@luphordhttps://github.com/luphord
linkhttps://docs.google.com/presentation/d/16VGNfVo6Kxk9lBhm1cx1-Jr19dqESyy10WkhtMgUeDY/
https://github.com/leonardo-m
leonardo-mhttps://github.com/leonardo-m
on Nov 27, 2020https://github.com/python/mypy/issues/3345#issuecomment-734707116
@luphordhttps://github.com/luphord
https://github.com/luphord
luphordhttps://github.com/luphord
on Nov 27, 2020https://github.com/python/mypy/issues/3345#issuecomment-734806022
@fyluxhttps://github.com/fylux
https://github.com/fylux
fyluxhttps://github.com/fylux
on Nov 27, 2020https://github.com/python/mypy/issues/3345#issuecomment-734872855
examplehttps://github.com/facebook/pyre-check/blob/master/documentation/examples/xlm/sources/main.py
https://mail.python.org/archives/list/typing-sig@python.org/thread/SQVTQYWIOI4TIO7NNBTFFWFMSMS2TA4J/https://mail.python.org/archives/list/typing-sig@python.org/thread/SQVTQYWIOI4TIO7NNBTFFWFMSMS2TA4J/
examplehttps://github.com/facebook/pyre-check/pull/330/files#diff-891797d87c1822a878781fdd9c4becbbf74d0fa40c1bc8a0932fa501bc7b1646R109
https://github.com/shaunc
shaunchttps://github.com/shaunc
on Apr 3, 2021https://github.com/python/mypy/issues/3345#issuecomment-812941515
https://github.com/fylux
fyluxhttps://github.com/fylux
on Apr 5, 2021https://github.com/python/mypy/issues/3345#issuecomment-813358527
@shaunchttps://github.com/shaunc
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Apr 5, 2021https://github.com/python/mypy/issues/3345#issuecomment-813534061
https://github.com/shaunc
shaunchttps://github.com/shaunc
on Apr 5, 2021https://github.com/python/mypy/issues/3345#issuecomment-813575875
https://github.com/samtygier-stfc
samtygier-stfchttps://github.com/samtygier-stfc
on May 13, 2025https://github.com/python/mypy/issues/3345#issuecomment-2877197585
python/typing#786https://github.com/python/typing/issues/786
https://github.com/sneakers-the-rat
sneakers-the-rathttps://github.com/sneakers-the-rat
on Jun 9, 2026https://github.com/python/mypy/issues/3345#issuecomment-4664544812
@fyluxhttps://github.com/fylux
numpydantichttps://github.com/p2p-ld/numpydantic
constraint solver docshttps://github.com/python/mypy/wiki/Type-Checker#constraint-solver
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/3345
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/3345
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%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.