René's URL Explorer Experiment


Title: isinstance + class indirectly deriving from SupportsInt results in "TypeError: Protocols cannot be used with isinstance()" · Issue #297 · python/typing · GitHub

Open Graph Title: isinstance + class indirectly deriving from SupportsInt results in "TypeError: Protocols cannot be used with isinstance()" · Issue #297 · python/typing

X Title: isinstance + class indirectly deriving from SupportsInt results in "TypeError: Protocols cannot be used with isinstance()" · Issue #297 · python/typing

Description: The following assumes mypy 0.4.5 and CPython 3.5.2. Let's have the code: # code3.py class C1: def __int__(self) -> int: return 42 class C2(C1): pass c = C2() print(int(c)) print(isinstance(c, C1)) The code works: % python code3.py 42 Tru...

Open Graph Description: The following assumes mypy 0.4.5 and CPython 3.5.2. Let's have the code: # code3.py class C1: def __int__(self) -> int: return 42 class C2(C1): pass c = C2() print(int(c)) print(isinstance(c, C1)) ...

X Description: The following assumes mypy 0.4.5 and CPython 3.5.2. Let's have the code: # code3.py class C1: def __int__(self) -> int: return 42 class C2(C1): pass c = C2() print(int(c)) print(isinstance(c...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"isinstance + class indirectly deriving from SupportsInt results in \"TypeError: Protocols cannot be used with isinstance()\"","articleBody":"The following assumes mypy 0.4.5 and CPython 3.5.2.\n\nLet's have the code:\n\n``` python\n# code3.py\nclass C1:\n\n    def __int__(self) -> int:\n        return 42\n\n\nclass C2(C1):\n    pass\n\n\nc = C2()\nprint(int(c))\nprint(isinstance(c, C1))\n```\n\nThe code works:\n\n```\n% python code3.py \n42\nTrue\n```\n\nmypy, however, will complain (as expected):\n\n```\n% mypy code3.py  \ncode3.py:12: error: Argument 1 to \"int\" has incompatible type \"C2\"; expected \"Union[SupportsInt, str, bytes]\"\n```\n\nLet's try to make mypy happy:\n\n``` python\n# code3.py\nfrom typing import SupportsInt\n\n\nclass C1(SupportsInt):\n\n    def __int__(self) -> int:\n        return 42\n\n\nclass C2(C1):\n    pass\n\n\nc = C2()\nprint(int(c))\nprint(isinstance(c, C1))\n```\n\nNow mypy is happy but the code fails at runtime:\n\n```\n% python code3.py\n42\nTraceback (most recent call last):\n  File \"code3.py\", line 16, in \u003cmodule>\n    print(isinstance(c, C1))\n  File \"/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/typing.py\", line 1269, in __instancecheck__\n    raise TypeError(\"Protocols cannot be used with isinstance().\")\nTypeError: Protocols cannot be used with isinstance().\n```\n\nIt seems that I'm put in a situation where I have to choose between static type safety and having the code actually work, am I missing something here? If not - what's the recommended solution to a problem like this?\n","author":{"url":"https://github.com/jstasiak","@type":"Person","name":"jstasiak"},"datePublished":"2016-10-12T17:17:37Z","url":"https://github.com/python/typing/issues/297"}

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:27aa8ec7-bb69-1265-1552-e45d0de65ef8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE82C:1CF166:20C377D:2C85F33:6B002115
html-safe-noncefa4bd8acc98e3940fdcb7889e6c7fc786cb9722769d40ae869c36ca8a2202e93
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODJDOjFDRjE2NjoyMEMzNzdEOjJDODVGMzM6NkIwMDIxMTUiLCJ2aXNpdG9yX2lkIjoiNjk3OTk5MTc2MDAwMDg2MjkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacb0f902466fcebd1c0de95bca444c57ae9b757f658851d67865033dccbaf44366
hovercard-subject-tagissue:182582839
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/297/issue_layout
twitter:imagehttps://opengraph.githubassets.com/722df08b46e6505f7c518c13b99b93896abb0610af83f6d81fc5acbc08b0628c/python/typing/issues/297
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/722df08b46e6505f7c518c13b99b93896abb0610af83f6d81fc5acbc08b0628c/python/typing/issues/297
og:image:altThe following assumes mypy 0.4.5 and CPython 3.5.2. Let's have the code: # code3.py class C1: def __int__(self) -> int: return 42 class C2(C1): pass c = C2() print(int(c)) print(isinstance(c, C1)) ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejstasiak
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
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
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/297#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F297
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%2F297
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/297
Reloadhttps://github.com/python/typing/issues/297
Reloadhttps://github.com/python/typing/issues/297
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/297
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/297
#330https://github.com/python/typing/pull/330
isinstance + class indirectly deriving from SupportsInt results in "TypeError: Protocols cannot be used with isinstance()"https://github.com/python/typing/issues/297#top
#330https://github.com/python/typing/pull/330
https://github.com/jstasiak
jstasiakhttps://github.com/jstasiak
on Oct 12, 2016https://github.com/python/typing/issues/297#issue-182582839
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 12, 2016https://github.com/python/typing/issues/297#issuecomment-253286995
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 12, 2016https://github.com/python/typing/issues/297#issuecomment-253289272
#295https://github.com/python/typing/pull/295
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Oct 12, 2016https://github.com/python/typing/issues/297#issuecomment-253301063
@gvanrossumhttps://github.com/gvanrossum
@JukkaLhttps://github.com/JukkaL
#11https://github.com/python/typing/issues/11
https://github.com/jstasiak
jstasiakhttps://github.com/jstasiak
on Oct 13, 2016https://github.com/python/typing/issues/297#issuecomment-253507532
@gvanrossumhttps://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
completedhttps://github.com/python/typing/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#330https://github.com/python/typing/pull/330
on Nov 19, 2016https://github.com/python/typing/issues/297#event-865380768
gvanrossumhttps://github.com/gvanrossum
on Nov 19, 2016https://github.com/python/typing/issues/297#event-865380770
Fix isinstance() for Protocols (#330)https://github.com/python/typing/commit/1881ffd3d1114c0563bf8d02ca7b8d1c6751bafa
#330https://github.com/python/typing/pull/330
https://docs.github.com/articles/closing-issues-via-commit-messages
1881ffdhttps://github.com/python/typing/commit/1881ffd3d1114c0563bf8d02ca7b8d1c6751bafa
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/297
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/297
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.