René's URL Explorer Experiment


Title: Incorrect inference with isinstance() · Issue #2993 · python/mypy · GitHub

Open Graph Title: Incorrect inference with isinstance() · Issue #2993 · python/mypy

X Title: Incorrect inference with isinstance() · Issue #2993 · python/mypy

Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.

Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.

X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect inference with isinstance()","articleBody":"I think there are a few problems with `isinstance` inference.\r\n\r\n1) This code type checks with `mypy --strcit --python-version 3.6`, but it should not:\r\n```\r\nfrom typing import *\r\ndef f(x: Union[int, str], typ: type) -> None:\r\n    if isinstance(x, (typ, int)):\r\n        print(x + 1)\r\n```\r\nThe semantic analyzer concludes that within the body of `if isinstance()`, the type of `x` must be `int`. It's not, however. For example, in this case `f('a', str)`, the `if` branch will be followed even though `x` is not an `int` (and this will cause runtime `TypeError` without any mypy warnings).\r\n\r\nThe reason this happens is that `type` annotation is represented as an `Instance` rather than as a `FunctionLike` inside  `checker.py:get_isinstance_type()`. As a result, it's skipped entirely in the loop, and only `int` is added to `types`, so sem analyzer thinks `x` must absolutely be `int`.\r\n\r\nOne solution is to make `type` represented with an instance of `CallableType` (why isn't it btw?!). Another solution is to simply add a bit of logic to the loop to properly handle this case.\r\n\r\n2) This code:\r\n```\r\ndef f(x: Union[int, str, List, Tuple]) -> None:\r\n    if isinstance(x, (str, (list, tuple))):\r\n        print(x[1])\r\n```\r\nresults in `error: Argument 2 to \"isinstance\" has incompatible type \"Tuple[str, Tuple[List[_T], Tuple[_T_co, ...]]]\"; expected \"Union[type, Tuple[type, ...]]\"`. \r\n\r\nThis is because there's this weird thing in python that allows to put *nested* tuples as the second argument to `isinstance`, and `mypy` (along with most other people) doesn't know about it. I don't know if it's worth fixing, but it's super easy (just flatten the second argument if it's a tuple).\r\n\r\nIf my understanding is correct, I'll make a PR.","author":{"url":"https://github.com/pkch","@type":"Person","name":"pkch"},"datePublished":"2017-03-14T09:29:42Z","url":"https://github.com/python/mypy/issues/2993"}

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/:user_id/:repository/issues/:id(.:format)
route-controllerissues
route-actionshow
fetch-noncev2:cde82943-4d46-2167-4eb5-2b15af4564df
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9E5A:F5AA9:22B6104:2F3CBC9:6B0029C9
html-safe-noncedf408c7a97350ea12756f86b09321ba647f690e44e81c5add3c6ded0fb02adc3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTVBOkY1QUE5OjIyQjYxMDQ6MkYzQ0JDOTo2QjAwMjlDOSIsInZpc2l0b3JfaWQiOiI0MTg3NDYxOTI1NjE5MTE2NDg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac0f705e16060b25965dddea83af088f3480be13f62aae89d0890f02609694489e
hovercard-subject-tagrepository:7053637
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///issues/show
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/mypy/issues/2993
twitter:imagehttps://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy
og:image:altOptional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
turbo-cache-controlno-cache
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
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/2993#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F2993
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%2F2993
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fissues%2Fshow&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/issues/2993
Reloadhttps://github.com/python/mypy/issues/2993
Reloadhttps://github.com/python/mypy/issues/2993
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/2993
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/2993
Incorrect inference with isinstance()https://github.com/python/mypy/issues/2993#top
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issue-214012619
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286373041
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286373335
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286375876
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286389663
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286504614
#2997https://github.com/python/mypy/pull/2997
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 14, 2017https://github.com/python/mypy/issues/2993#issuecomment-286509236
#2997https://github.com/python/mypy/pull/2997
#2994https://github.com/python/mypy/issues/2994
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#2997https://github.com/python/mypy/pull/2997
on Mar 19, 2017https://github.com/python/mypy/issues/2993#event-1005979668
https://github.com/pkch
pkchhttps://github.com/pkch
on Apr 21, 2017https://github.com/python/mypy/issues/2993#issuecomment-296314413
#2997https://github.com/python/mypy/pull/2997
#2995https://github.com/python/mypy/pull/2995
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/2993
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/2993
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.