René's URL Explorer Experiment


Title: extremely slow type checking for constrained `TypeVars` and overloads on generic classes · Issue #20439 · python/mypy · GitHub

Open Graph Title: extremely slow type checking for constrained `TypeVars` and overloads on generic classes · Issue #20439 · python/mypy

X Title: extremely slow type checking for constrained `TypeVars` and overloads on generic classes · Issue #20439 · python/mypy

Description: I'm seeing extremely slow type-checking (around 1–2 minutes) for a very small, self-contained example involving constrained TypeVars, generic subclasses, and many overloads. The code produces no errors but mypy appears to spend a disprop...

Open Graph Description: I'm seeing extremely slow type-checking (around 1–2 minutes) for a very small, self-contained example involving constrained TypeVars, generic subclasses, and many overloads. The code produces no er...

X Description: I'm seeing extremely slow type-checking (around 1–2 minutes) for a very small, self-contained example involving constrained TypeVars, generic subclasses, and many overloads. The code produces n...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"extremely slow type checking for constrained `TypeVars` and overloads on generic classes","articleBody":"I'm seeing extremely slow type-checking (around 1–2 minutes) for a very small, self-contained example involving constrained `TypeVar`s, generic subclasses, and many overloads. The code produces no errors but mypy appears to spend a disproportionate amount of time resolving types.\n\nThe example defines two `TypeVar`s constrained to ~15 `Literal[str]` values, a generic base class `Pbase[T]`, several subclasses `P1[T]` … `P14[T]`, and a generic class `Fn[T1, T2]` whose `call` method is overloaded to preserve the concrete subclass while transforming the type parameter. The full reproduction is below.\n\n```python\nimport typing as t\n\n\nclass LetterT:\n    A = t.Literal[\"a\"]\n    B = t.Literal[\"b\"]\n    C = t.Literal[\"c\"]\n    D = t.Literal[\"d\"]\n    E = t.Literal[\"e\"]\n    F = t.Literal[\"f\"]\n    G = t.Literal[\"g\"]\n    H = t.Literal[\"h\"]\n    I = t.Literal[\"i\"]\n    J = t.Literal[\"j\"]\n    K = t.Literal[\"k\"]\n    L = t.Literal[\"l\"]\n    M = t.Literal[\"m\"]\n    N = t.Literal[\"n\"]\n    O = t.Literal[\"o\"]\n\n\nT1 = t.TypeVar(\n    \"T1\",\n    LetterT.A,\n    LetterT.B,\n    LetterT.C,\n    LetterT.D,\n    LetterT.E,\n    LetterT.F,\n    LetterT.G,\n    LetterT.H,\n    LetterT.I,\n    LetterT.J,\n    LetterT.K,\n    LetterT.L,\n    LetterT.M,\n    LetterT.N,\n    LetterT.O,\n)\nT2 = t.TypeVar(\n    \"T2\",\n    LetterT.A,\n    LetterT.B,\n    LetterT.C,\n    LetterT.D,\n    LetterT.E,\n    LetterT.F,\n    LetterT.G,\n    LetterT.H,\n    LetterT.I,\n    LetterT.J,\n    LetterT.K,\n    LetterT.L,\n    LetterT.M,\n    LetterT.N,\n    LetterT.O,\n)\n\n\nclass Pbase(t.Generic[T1]):\n    def __init__(self, v: T1) -> None:\n        self.v: T1 = v\n\n\nclass P1(Pbase[T1]): ...\nclass P2(Pbase[T1]): ...\nclass P3(Pbase[T1]): ...\nclass P4(Pbase[T1]): ...\nclass P5(Pbase[T1]): ...\nclass P6(Pbase[T1]): ...\nclass P7(Pbase[T1]): ...\nclass P8(Pbase[T1]): ...\nclass P9(Pbase[T1]): ...\nclass P10(Pbase[T1]): ...\nclass P11(Pbase[T1]): ...\nclass P12(Pbase[T1]): ...\nclass P13(Pbase[T1]): ...\nclass P14(Pbase[T1]): ...\n\n\nclass Fn(t.Generic[T1, T2]):\n    def __init__(self, a: T1, b: T2) -> None:\n        self.a: T1 = a\n        self.b: T2 = b\n\n    @t.overload\n    def call(self, p: P1[T1]) -> P1[T2]: ...\n    @t.overload\n    def call(self, p: P2[T1]) -> P2[T2]: ...\n    @t.overload\n    def call(self, p: P3[T1]) -> P3[T2]: ...\n    @t.overload\n    def call(self, p: P4[T1]) -> P4[T2]: ...\n    @t.overload\n    def call(self, p: P5[T1]) -> P5[T2]: ...\n    @t.overload\n    def call(self, p: P6[T1]) -> P6[T2]: ...\n    @t.overload\n    def call(self, p: P7[T1]) -> P7[T2]: ...\n    @t.overload\n    def call(self, p: P8[T1]) -> P8[T2]: ...\n    @t.overload\n    def call(self, p: P9[T1]) -> P9[T2]: ...\n    @t.overload\n    def call(self, p: P10[T1]) -> P10[T2]: ...\n    @t.overload\n    def call(self, p: P11[T1]) -> P11[T2]: ...\n    @t.overload\n    def call(self, p: P12[T1]) -> P12[T2]: ...\n    @t.overload\n    def call(self, p: P13[T1]) -> P13[T2]: ...\n    @t.overload\n    def call(self, p: P14[T1]) -> P14[T2]: ...\n\n    def call(self, p):  # type: ignore[no-untyped-def]\n        return Fn(self.b, p.v)\n```\n\nRunning `mypy repro.py --no-incremental` consistently takes on the order of minutes on my machine. Removing any one of the following makes the runtime drop back to normal: the `Literal` constraints, the number of overloads, or the generic subclass hierarchy. This suggests a combinatorial blow-up in constraint solving and/or overload resolution. While using a bounded `TypeVar` instead of explicit constraints does improve performance, that is not a viable option in my case, as I need to parameterize these classes with precise, concrete `Literal` types rather than a common upper bound.\n\nThis is primarily a performance report; I'm not sure whether this is a known limitation or an opportunity for optimization, but the scaling behavior seems unexpectedly poor for such a small input.\n\nI also attach the command I used to benchmark type checking time.\n\n```console\n$ time mypy repro.py --no-incremental\n\nreal    1m44.220s\nuser    1m44.065s\nsys     0m1.409s\n```\n\nAny ideas what might be the issue? How hard would it be to solve it?","author":{"url":"https://github.com/quczer","@type":"Person","name":"quczer"},"datePublished":"2025-12-18T13:21:19Z","url":"https://github.com/python/mypy/issues/20439"}

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:96d4493a-065f-02e4-5d62-a9d73f3cf4fe
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA350:BACA4:2C7448B:3ABD89D:6B001F8D
html-safe-nonce9416cb106d0a979ead3162a119ebcd663a06cb0a31a6c26824e1391976bb3ed2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzUwOkJBQ0E0OjJDNzQ0OEI6M0FCRDg5RDo2QjAwMUY4RCIsInZpc2l0b3JfaWQiOiI3Njk0MzIxMDg4MDgzMjcxNTY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac5e39df56cc4a18ae23d7333840c90cf86eb8ced15a2ac5629491a1980acf1f22
hovercard-subject-tagissue:3743147012
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/20439/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d28006d514a97c00627b8922fe13b367aa64209279fa750a1dbc2775ce389928/python/mypy/issues/20439
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d28006d514a97c00627b8922fe13b367aa64209279fa750a1dbc2775ce389928/python/mypy/issues/20439
og:image:altI'm seeing extremely slow type-checking (around 1–2 minutes) for a very small, self-contained example involving constrained TypeVars, generic subclasses, and many overloads. The code produces no er...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamequczer
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
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
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/20439#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F20439
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%2F20439
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/20439
Reloadhttps://github.com/python/mypy/issues/20439
Reloadhttps://github.com/python/mypy/issues/20439
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 requests546 (546)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/20439
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/20439
#22393https://github.com/python/mypy/pull/22393
extremely slow type checking for constrained TypeVars and overloads on generic classeshttps://github.com/python/mypy/issues/20439#top
#22393https://github.com/python/mypy/pull/22393
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
topic-overloadshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-overloads%22
topic-type-variableshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-type-variables%22
https://github.com/quczer
quczerhttps://github.com/quczer
on Dec 18, 2025https://github.com/python/mypy/issues/20439#issue-3743147012
https://github.com/A5rocks
A5rockshttps://github.com/A5rocks
on Dec 18, 2025https://github.com/python/mypy/issues/20439#issuecomment-3671816235
A5rockshttps://github.com/A5rocks
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
on Dec 18, 2025https://github.com/python/mypy/issues/20439#event-21651993209
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Dec 19, 2025https://github.com/python/mypy/issues/20439#issuecomment-3673458648
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Dec 19, 2025https://github.com/python/mypy/issues/20439#issuecomment-3673513253
@ilevkivskyihttps://github.com/ilevkivskyi
#17392https://github.com/python/mypy/pull/17392
https://github.com/A5rocks
A5rockshttps://github.com/A5rocks
on Dec 19, 2025https://github.com/python/mypy/issues/20439#issuecomment-3674562206
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Dec 20, 2025https://github.com/python/mypy/issues/20439#issuecomment-3677073976
nipunn1313/mypy-protobuf#707https://github.com/nipunn1313/mypy-protobuf/issues/707
#15865https://github.com/python/mypy/pull/15865
ilevkivskyihttps://github.com/ilevkivskyi
topic-overloadshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-overloads%22
topic-type-variableshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-type-variables%22
on Dec 20, 2025https://github.com/python/mypy/issues/20439#event-21680968049
https://github.com/quczer
quczerhttps://github.com/quczer
on Dec 22, 2025https://github.com/python/mypy/issues/20439#issuecomment-3681946501
https://github.com/quczer
quczerhttps://github.com/quczer
on Jan 22, 2026https://github.com/python/mypy/issues/20439#issuecomment-3785299069
@A5rockshttps://github.com/A5rocks
@hauntsaninjahttps://github.com/hauntsaninja
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Jan 22, 2026https://github.com/python/mypy/issues/20439#issuecomment-3785357019
hauntsaninjahttps://github.com/hauntsaninja
on Nov 7, 2026https://github.com/python/mypy/issues/20439#event-35462355006
Prevent quadratic runtime with generic overloadshttps://github.com/hauntsaninja/mypy/commit/4c0024b86f848d1c2fe582e1c6909dee3877add0
https://docs.github.com/articles/closing-issues-via-commit-messages
4c0024bhttps://github.com/hauntsaninja/mypy/commit/4c0024b86f848d1c2fe582e1c6909dee3877add0
Prevent quadratic runtime with generic overloadshttps://github.com/hauntsaninja/mypy/commit/ce5d0ffe658a93aab04de76116c8ddb73e236837
https://docs.github.com/articles/closing-issues-via-commit-messages
ce5d0ffhttps://github.com/hauntsaninja/mypy/commit/ce5d0ffe658a93aab04de76116c8ddb73e236837
Prevent quadratic runtime with generic overloadshttps://github.com/hauntsaninja/mypy/commit/a54ffb77d0938a92f1a85c655ff6dfc9af83f130
https://docs.github.com/articles/closing-issues-via-commit-messages
a54ffb7https://github.com/hauntsaninja/mypy/commit/a54ffb77d0938a92f1a85c655ff6dfc9af83f130
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/20439
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/20439
performancehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22performance%22
topic-overloadshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-overloads%22
topic-type-variableshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-type-variables%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.