René's URL Explorer Experiment


Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy · GitHub

Open Graph Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy

X Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy

Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Type of x is 'int' here else: x = '' # No e...

Open Graph Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ...

X Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Infer union from conditional definition in if statement","articleBody":"Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using `--allow-redefinitions`):\r\n\r\n```py\r\nif foo():\r\n    x = 0\r\n    # Type of x is 'int' here\r\nelse:\r\n    x = ''  # No error here\r\n    # Type of x is 'str' here\r\nreveal_type(x)  # Union[int, str]\r\n```\r\n\r\nCurrently the second assignment generates an error, and the type of `x` is `int` everywhere.\r\n\r\nThis is a generalization of #6232 and related to #1174 (but not a direct follow-up issue).","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2019-01-21T12:30:22Z","url":"https://github.com/python/mypy/issues/6233"}

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:a1e99588-54c7-604a-6309-3fe892364f06
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDEC6:31F9AC:2261E7:2FE31F:6B00687C
html-safe-noncecc2d05dfac76c85bc5998db1c397d927bca261b0659df117856048f1175b7374
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUM2OjMxRjlBQzoyMjYxRTc6MkZFMzFGOjZCMDA2ODdDIiwidmlzaXRvcl9pZCI6IjY0ODgxMzY4NDM2MzUyMjI2NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac01d5a8fe6d511fa24ceeab07fe85b52fee5ba426766627490b125a32074a5b01
hovercard-subject-tagissue:401332414
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/6233/issue_layout
twitter:imagehttps://opengraph.githubassets.com/678e445de67c3363a8a1256b0ae0c572c177fd68f64600791415fdb9b7d5e823/python/mypy/issues/6233
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/678e445de67c3363a8a1256b0ae0c572c177fd68f64600791415fdb9b7d5e823/python/mypy/issues/6233
og:image:altMaybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJukkaL
hostnamegithub.com
expected-hostnamegithub.com
None6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa
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
release46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/6233#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F6233
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%2F6233
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/6233
Reloadhttps://github.com/python/mypy/issues/6233
Reloadhttps://github.com/python/mypy/issues/6233
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 requests543 (543)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/6233
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/6233
#18727https://github.com/python/mypy/pull/18727
Infer union from conditional definition in if statementhttps://github.com/python/mypy/issues/6233#top
#18727https://github.com/python/mypy/pull/18727
https://github.com/JukkaL
false-positivemypy gave an error on correct codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22false-positive%22
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 21, 2019https://github.com/python/mypy/issues/6233#issue-401332414
#6232https://github.com/python/mypy/issues/6232
#1174https://github.com/python/mypy/issues/1174
Nexthttps://github.com/python/mypy/issues/6233?timeline_page=1
JukkaLhttps://github.com/JukkaL
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-1-normalhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-1-normal%22
false-positivemypy gave an error on correct codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22false-positive%22
on Jan 21, 2019https://github.com/python/mypy/issues/6233#event-2086273126
https://github.com/bluetech
bluetechhttps://github.com/bluetech
on Jan 27, 2019https://github.com/python/mypy/issues/6233#issuecomment-457896632
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Jan 27, 2019https://github.com/python/mypy/issues/6233#issuecomment-457903758
@bluetechhttps://github.com/bluetech
https://github.com/bluetech
bluetechhttps://github.com/bluetech
on Jan 27, 2019https://github.com/python/mypy/issues/6233#issuecomment-457907351
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 28, 2019https://github.com/python/mypy/issues/6233#issuecomment-458175509
@bluetechhttps://github.com/bluetech
https://github.com/dumblob
dumblobhttps://github.com/dumblob
on Jan 7, 2020https://github.com/python/mypy/issues/6233#issuecomment-571600947
https://github.com/aperiodic
aperiodichttps://github.com/aperiodic
on Jan 9, 2020https://github.com/python/mypy/issues/6233#issuecomment-572778317
https://github.com/msullivan
msullivanhttps://github.com/msullivan
on Jan 10, 2020https://github.com/python/mypy/issues/6233#issuecomment-572831636
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 13, 2020https://github.com/python/mypy/issues/6233#issuecomment-573649461
@msullivanhttps://github.com/msullivan
@aperiodichttps://github.com/aperiodic
JukkaLhttps://github.com/JukkaL
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
priority-1-normalhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-1-normal%22
on Jan 13, 2020https://github.com/python/mypy/issues/6233#event-2943059742
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 13, 2020https://github.com/python/mypy/issues/6233#issuecomment-573649791
https://github.com/aperiodic
aperiodichttps://github.com/aperiodic
on Jan 15, 2020https://github.com/python/mypy/issues/6233#issuecomment-574810544
https://github.com/unordinateur
unordinateurhttps://github.com/unordinateur
on Jan 15, 2020https://github.com/python/mypy/issues/6233#issuecomment-574836800
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 16, 2020https://github.com/python/mypy/issues/6233#issuecomment-575141680
@unordinateurhttps://github.com/unordinateur
https://github.com/unordinateur
unordinateurhttps://github.com/unordinateur
on Jan 16, 2020https://github.com/python/mypy/issues/6233#issuecomment-575247966
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 17, 2020https://github.com/python/mypy/issues/6233#issuecomment-575596203
@unordinateurhttps://github.com/unordinateur
https://github.com/unordinateur
unordinateurhttps://github.com/unordinateur
on Jan 18, 2020https://github.com/python/mypy/issues/6233#issuecomment-575883600
https://github.com/gtarabat
gtarabathttps://github.com/gtarabat
on Oct 27, 2022https://github.com/python/mypy/issues/6233#issuecomment-1293336859
https://github.com/randolf-scholz
randolf-scholzhttps://github.com/randolf-scholz
on Nov 14, 2022https://github.com/python/mypy/issues/6233#issuecomment-1313723894
https://mypy-play.net/?mypy=latest&python=3.10&gist=45faed499d453baccdb671b4985facb0https://mypy-play.net/?mypy=latest&python=3.10&gist=45faed499d453baccdb671b4985facb0
JukkaLhttps://github.com/JukkaL
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
on Jun 2, 2023https://github.com/python/mypy/issues/6233#event-9414987763
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jun 2, 2023https://github.com/python/mypy/issues/6233#issuecomment-1573833456
JukkaLhttps://github.com/JukkaL
on Jan 23, 2025https://github.com/python/mypy/issues/6233#event-16045735165
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jan 23, 2025https://github.com/python/mypy/issues/6233#issuecomment-2610122935
#6232https://github.com/python/mypy/issues/6232
JukkaLhttps://github.com/JukkaL
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%22
on Jan 23, 2025https://github.com/python/mypy/issues/6233#event-16045760661
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#18727https://github.com/python/mypy/pull/18727
on Mar 19, 2025https://github.com/python/mypy/issues/6233#event-16861589617
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
34e8c7chttps://github.com/python/mypy/commit/34e8c7c5fa09516fbed37cad80b161906e97f53a
on Mar 19, 2025https://github.com/python/mypy/issues/6233#event-16861589831
cdce8phttps://github.com/cdce8p
on Mar 19, 2025https://github.com/python/mypy/issues/6233#event-16862382222
Add flag to allow more flexible variable redefinition (python#18727)https://github.com/cdce8p/mypy/commit/34e8c7c5fa09516fbed37cad80b161906e97f53a
python#18727https://github.com/python/mypy/pull/18727
https://docs.github.com/articles/closing-issues-via-commit-messages
34e8c7chttps://github.com/cdce8p/mypy/commit/34e8c7c5fa09516fbed37cad80b161906e97f53a
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/6233
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/6233
JukkaLhttps://github.com/JukkaL
false-positivemypy gave an error on correct codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22false-positive%22
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
priority-0-highhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-0-high%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.