René's URL Explorer Experiment


Title: Endless call cycle between is_callable_compatible and is_protocol_implementation · Issue #21739 · python/mypy · GitHub

Open Graph Title: Endless call cycle between is_callable_compatible and is_protocol_implementation · Issue #21739 · python/mypy

X Title: Endless call cycle between is_callable_compatible and is_protocol_implementation · Issue #21739 · python/mypy

Description: Discovered by @glyph and I see it's not his first rodeo (#18195 for instance). My best interpretation (which could be wrong) is that a generic class which references itself in a method's type annotation, when typed using a protocol, will...

Open Graph Description: Discovered by @glyph and I see it's not his first rodeo (#18195 for instance). My best interpretation (which could be wrong) is that a generic class which references itself in a method's type annot...

X Description: Discovered by @glyph and I see it's not his first rodeo (#18195 for instance). My best interpretation (which could be wrong) is that a generic class which references itself in a method's ty...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Endless call cycle between is_callable_compatible and is_protocol_implementation","articleBody":"Discovered by @glyph and I see it's not his first rodeo (https://github.com/python/mypy/issues/18195 for instance).\n\nMy best interpretation (which could be wrong) is that a generic class which references itself in a method's type annotation, when typed using a protocol, will cause mypy to loop endlessly between matching the protocol and checking the types in the class.  I haven't pinpointed the exact mechanism but it kind of makes sense that this could happen.\n\n**To Reproduce**\n\nThe original code is here: https://github.com/glyph/OmniFocusStreamCounter/commit/454d0727363595b770cb150cc08a0018bc04a783\n\nBut this is about as far as I could reduce it:\n\n```python\nfrom dataclasses import dataclass\nfrom typing import Any, Callable, Protocol\n\n\nclass PExp[T](Protocol):\n    def EQ(self, other: T) -> PExp[T]: ...\n\n\nclass PRef[T](Protocol):\n    def EQ(self, other: T) -> PExp[T]: ...\n\n\n@dataclass\nclass Exp[A, B]:\n    _left: A\n    _op: str\n    _right: B\n\n    def EQ(self, other: Any) -> Exp[Exp[A, B], Any]:\n        return Exp(self, \"EQ\", other)\n\n\n@dataclass\nclass Ref[T]:\n    get: Callable[[], T]\n\n    def EQ(self, other: T) -> Exp[Ref[T], T]:\n        return Exp(self, \"EQ\", other)\n\n\n@dataclass\nclass Cache:\n    def spam(self, name: str) -> PRef[str]:\n        return Ref(lambda: \"spam\")\n\n```\n\n**Expected Behavior**\n\nSo, if you make `Exp.EQ` untyped, then mypy will succeed (I fixed some problems in the original code 😉 )  This is obviously the expected behaviour.\n\n**Actual Behavior**\n\nRunning mypy from HEAD, uncompiled, with --show-traceback - it hangs, then on Ctrl-C we see, this, endlessly:\n\n```\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 1281, in is_protocol_implementation                                                              07:44:34 [233/1846]\n    is_compat = is_subtype(                                                                                                                                             \n        subtype, supertype, ignore_pos_arg_names=ignore_names, options=options                                                                                          \n    )                                                                                                                                                                   \n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 189, in is_subtype                                                                                                  \n    return _is_subtype(left, right, subtype_context, proper_subtype=False)                                                                                              \n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 376, in _is_subtype                                                                                                 \n    return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))\n           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/dhd/work/mypy/mypy/types.py\", line 2361, in accept\n    return visitor.visit_callable_type(self)\n           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 740, in visit_callable_type\n    return is_callable_compatible(\n        left,\n    ...\u003c8 lines>...\n        ),\n    )\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 1785, in is_callable_compatible\n    if not ignore_return and not is_compat_return(left.ret_type, right.ret_type):\n                                 ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 448, in _is_subtype\n    return is_subtype(left, right, subtype_context=self.subtype_context)\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 189, in is_subtype\n    return _is_subtype(left, right, subtype_context, proper_subtype=False)\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 376, in _is_subtype\n    return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))\n           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/dhd/work/mypy/mypy/types.py\", line 1684, in accept\n    return visitor.visit_instance(self)\n           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n  File \"/home/dhd/work/mypy/mypy/subtypes.py\", line 627, in visit_instance\n    if right.type.is_protocol and is_protocol_implementation(\n                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~^\n        left, right, proper_subtype=self.proper_subtype, options=self.options\n        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n    ):\n    ^\n```\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: mypy 2.4.0+dev.67eecf07fea3fa4bbaab9d46cd28372a8ded330b (compiled: no)\n- Mypy command-line flags: --show-traceback -v\n- Mypy configuration options from `mypy.ini` (and other config files):\n```toml\n[tool.mypy]\nnamespace_packages = true\nplugins = [\"mypy_zope:plugin\"]\n\n[[tool.mypy.overrides]]\nignore_missing_imports = true\nmodule = [\n  \"objc\",\n  \"Foundation\",\n  \"AppKit\",\n  \"ServiceManagement\",\n  \"setuptools\",\n  \"appscript\",\n]\n```\n- Python version used: 3.14\n \n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\n","author":{"url":"https://github.com/dhdaines","@type":"Person","name":"dhdaines"},"datePublished":"2026-07-16T11:47:02Z","url":"https://github.com/python/mypy/issues/21739"}

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:3d3913c8-0abc-b2d7-5b24-dda1444c76a1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEC5E:2463C6:2E5F1E:3E8475:6B0026AA
html-safe-nonce1e29fa9172003289d2d40a6de39ac7e544892f8c6dbee97f4ecbbf5631cccf3c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzVFOjI0NjNDNjoyRTVGMUU6M0U4NDc1OjZCMDAyNkFBIiwidmlzaXRvcl9pZCI6IjU2ODQyNjkzNzEyODM3NDQ0MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac47d161033ed4e029ed88c43d029a93b563e76d094781ef4e56535157cdbc9ebb
hovercard-subject-tagissue:4901668010
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/21739/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5df4652f55eddc75f9521e1ba1c87157abe21dd6c68888e4a686175a4b561662/python/mypy/issues/21739
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5df4652f55eddc75f9521e1ba1c87157abe21dd6c68888e4a686175a4b561662/python/mypy/issues/21739
og:image:altDiscovered by @glyph and I see it's not his first rodeo (#18195 for instance). My best interpretation (which could be wrong) is that a generic class which references itself in a method's type annot...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedhdaines
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/21739#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F21739
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%2F21739
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/21739
Reloadhttps://github.com/python/mypy/issues/21739
Reloadhttps://github.com/python/mypy/issues/21739
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/21739
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/21739
#22036https://github.com/python/mypy/pull/22036
Endless call cycle between is_callable_compatible and is_protocol_implementationhttps://github.com/python/mypy/issues/21739#top
#22036https://github.com/python/mypy/pull/22036
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
crashhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22crash%22
topic-protocolshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-protocols%22
topic-recursive-typeshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-recursive-types%22
https://github.com/dhdaines
dhdaineshttps://github.com/dhdaines
on Jul 16, 2026https://github.com/python/mypy/issues/21739#issue-4901668010
@glyphhttps://github.com/glyph
#18195https://github.com/python/mypy/issues/18195
glyph/OmniFocusStreamCounter@454d072https://github.com/glyph/OmniFocusStreamCounter/commit/454d0727363595b770cb150cc08a0018bc04a783
dhdaineshttps://github.com/dhdaines
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
on Jul 16, 2026https://github.com/python/mypy/issues/21739#event-28067097280
ilevkivskyihttps://github.com/ilevkivskyi
crashhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22crash%22
topic-protocolshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-protocols%22
topic-recursive-typeshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-recursive-types%22
on Jul 16, 2026https://github.com/python/mypy/issues/21739#event-28068397556
https://github.com/dhdaines
dhdaineshttps://github.com/dhdaines
on Jul 16, 2026https://github.com/python/mypy/issues/21739#issuecomment-4991874696
ilevkivskyihttps://github.com/ilevkivskyi
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
865308bhttps://github.com/python/mypy/commit/865308bdf5be0f9be6baf6dd919e512eeb7b0007
on Sep 24, 2026https://github.com/python/mypy/issues/21739#event-31797334528
ilevkivskyihttps://github.com/ilevkivskyi
on Sep 24, 2026https://github.com/python/mypy/issues/21739#event-31797588963
Handle diverging protocol (python#22036)https://github.com/ilevkivskyi/mypy/commit/865308bdf5be0f9be6baf6dd919e512eeb7b0007
python#22036https://github.com/python/mypy/pull/22036
865308bhttps://github.com/ilevkivskyi/mypy/commit/865308bdf5be0f9be6baf6dd919e512eeb7b0007
https://github.com/glyph
glyphhttps://github.com/glyph
on Sep 25, 2026https://github.com/python/mypy/issues/21739#issuecomment-5828239244
@ilevkivskyihttps://github.com/ilevkivskyi
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/21739
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/21739
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
crashhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22crash%22
topic-protocolshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-protocols%22
topic-recursive-typeshttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-recursive-types%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.