René's URL Explorer Experiment


Title: Error when checking function conditionally defined in try/except/else clause · Issue #1289 · python/mypy · GitHub

Open Graph Title: Error when checking function conditionally defined in try/except/else clause · Issue #1289 · python/mypy

X Title: Error when checking function conditionally defined in try/except/else clause · Issue #1289 · python/mypy

Description: The following code causes mypy to crash: def fun1(): pass try: pass except: fun2 = fun1 else: def fun2(): pass Traceback: Traceback (most recent call last): File "./scripts/mypy", line 6, in main(__file__) File "mypy/mypy/main.p...

Open Graph Description: The following code causes mypy to crash: def fun1(): pass try: pass except: fun2 = fun1 else: def fun2(): pass Traceback: Traceback (most recent call last): File "./scripts/mypy", line 6, in

X Description: The following code causes mypy to crash: def fun1(): pass try: pass except: fun2 = fun1 else: def fun2(): pass Traceback: Traceback (most recent call last): File "./scripts/mypy", line 6,...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Error when checking function conditionally defined in try/except/else clause","articleBody":"The following code causes mypy to crash:\n\n``` python\ndef fun1():\n    pass\n\ntry:\n    pass\nexcept:\n    fun2 = fun1\nelse:\n    def fun2():\n        pass\n```\n\nTraceback:\n\n``` pytb\nTraceback (most recent call last):\n  File \"./scripts/mypy\", line 6, in \u003cmodule>\n    main(__file__)\n  File \"mypy/mypy/main.py\", line 50, in main\n    type_check_only(sources, bin_dir, options)\n  File \"mypy/mypy/main.py\", line 94, in type_check_only\n    python_path=options.python_path)\n  File \"mypy/mypy/build.py\", line 210, in build\n    result = manager.process(initial_states)\n  File \"mypy/mypy/build.py\", line 425, in process\n    next.process()\n  File \"mypy/mypy/build.py\", line 930, in process\n    self.type_checker().visit_file(self.tree, self.tree.path)\n  File \"mypy/mypy/checker.py\", line 409, in visit_file\n    self.accept(d)\n  File \"mypy/mypy/checker.py\", line 450, in accept\n    typ = node.accept(self)\n  File \"mypy/mypy/nodes.py\", line 707, in accept\n    return visitor.visit_try_stmt(self)\n  File \"mypy/mypy/checker.py\", line 1732, in visit_try_stmt\n    self.accept(s.else_body)\n  File \"mypy/mypy/checker.py\", line 450, in accept\n    typ = node.accept(self)\n  File \"mypy/mypy/nodes.py\", line 526, in accept\n    return visitor.visit_block(self)\n  File \"mypy/mypy/checker.py\", line 1113, in visit_block\n    self.accept(s)\n  File \"mypy/mypy/checker.py\", line 450, in accept\n    typ = node.accept(self)\n  File \"mypy/mypy/nodes.py\", line 382, in accept\n    return visitor.visit_func_def(self)\n  File \"mypy/mypy/checker.py\", line 594, in visit_func_def\n    'redefinition with type')\n  File \"mypy/mypy/checker.py\", line 2117, in check_subtype\n    if not is_subtype(subtype, supertype):\n  File \"mypy/mypy/subtypes.py\", line 49, in is_subtype\n    return left.accept(SubtypeVisitor(right, type_parameter_checker))\nAttributeError: 'NoneType' object has no attribute 'accept'\n```\n\nI'm still trying to understand the code and why it might be crashing. As a side issue, one thing I find odd is that presumably when mypy checks itself, it isn't seeing that `TypeChecker.check_subtype()` doesn't accept `None` for the first argument (it accepts `Type` but doesn't specify it using `Optional`). When it's called, the first argument is defined like this:\n\n``` python\norig_type = defn.original_def.type\n```\n\nWhere `defn` is of the type `mypy.nodes.FuncDef`. `FuncDef.original_def` is of the type `Union[mypy.nodes.FuncDef, mypy.nodes.Var]`. `FuncDef.type` and `Var.type` are of the type `Optional[mypy.types.Type]` (both fields are optional because they're set to `None` on their respective classes).\n\nShouldn't the checker, using type inference when `orig_type` is defined, catch that type mismatch when `TypeChecker.check_subtype()` is called?\n\nEdit: I suppose my digression above might be invalid if all types are nullable, but while PEP 484 states, \"[b]y default, None is an invalid value for any type, unless a default value of None has been provided in the function definition\", the mypy docs say, \"None is a valid value for every type, which resembles null in Java.\" Are the mypy docs out of date/incorrect, or is every type nullable?\n","author":{"url":"https://github.com/aiiie","@type":"Person","name":"aiiie"},"datePublished":"2016-03-12T09:46:19Z","url":"https://github.com/python/mypy/issues/1289"}

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:30cdf9a5-c56d-ab50-067a-ee39afabe259
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD960:37308E:274D924:339620D:6B0005FC
html-safe-nonce5395f28044bd12edb43bbd8a8a25b35843f3a4d72db9607eeece4895d2d297bc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTYwOjM3MzA4RToyNzREOTI0OjMzOTYyMEQ6NkIwMDA1RkMiLCJ2aXNpdG9yX2lkIjoiNTQzNzI5NzMyNzE1MDcyODcwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac44a5225cb8dd329671d7c404559e37686cc965a2350d04a28ef01fcd13734f00
hovercard-subject-tagissue:140367368
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/1289/issue_layout
twitter:imagehttps://opengraph.githubassets.com/83b018cf932e7869c3c278e7ac10c52d3bbad2465757f2f2fc9a5077be64e489/python/mypy/issues/1289
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/83b018cf932e7869c3c278e7ac10c52d3bbad2465757f2f2fc9a5077be64e489/python/mypy/issues/1289
og:image:altThe following code causes mypy to crash: def fun1(): pass try: pass except: fun2 = fun1 else: def fun2(): pass Traceback: Traceback (most recent call last): File "./scripts/mypy", line 6, in
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaiiie
hostnamegithub.com
expected-hostnamegithub.com
None0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729
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
release16a11879678aaf97e2a42c33ee70830aa084fa37
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/1289#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F1289
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%2F1289
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/1289
Reloadhttps://github.com/python/mypy/issues/1289
Reloadhttps://github.com/python/mypy/issues/1289
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/1289
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/1289
Error when checking function conditionally defined in try/except/else clausehttps://github.com/python/mypy/issues/1289#top
https://github.com/rwbarton
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/aiiie
aiiiehttps://github.com/aiiie
on Mar 12, 2016https://github.com/python/mypy/issues/1289#issue-140367368
gvanrossumhttps://github.com/gvanrossum
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
on Mar 17, 2016https://github.com/python/mypy/issues/1289#event-594053093
https://github.com/ddfisher
ddfisherhttps://github.com/ddfisher
on Mar 17, 2016https://github.com/python/mypy/issues/1289#issuecomment-198081186
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Mar 17, 2016https://github.com/python/mypy/issues/1289#issuecomment-198081297
#1297https://github.com/python/mypy/issues/1297
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Mar 17, 2016https://github.com/python/mypy/issues/1289#issuecomment-198081872
#1297https://github.com/python/mypy/issues/1297
gvanrossumhttps://github.com/gvanrossum
on Mar 17, 2016https://github.com/python/mypy/issues/1289#event-594059739
https://github.com/aiiie
aiiiehttps://github.com/aiiie
on Mar 18, 2016https://github.com/python/mypy/issues/1289#issuecomment-198248090
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Mar 18, 2016https://github.com/python/mypy/issues/1289#issuecomment-198353390
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Apr 21, 2016https://github.com/python/mypy/issues/1289#issuecomment-212904505
gvanrossumhttps://github.com/gvanrossum
on Apr 22, 2016https://github.com/python/mypy/issues/1289#event-638256001
Correctly type check redefinitions in try's else clause.https://github.com/python/mypy/commit/0b5efee728ba64d644299d35a82b6cf5ccbc8d3f
https://docs.github.com/articles/closing-issues-via-commit-messages
0b5efeehttps://github.com/python/mypy/commit/0b5efee728ba64d644299d35a82b6cf5ccbc8d3f
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Apr 22, 2016https://github.com/python/mypy/issues/1289#issuecomment-213591824
@Brodiehttps://github.com/Brodie
@jukkahttps://github.com/jukka
gvanrossumhttps://github.com/gvanrossum
on Apr 22, 2016https://github.com/python/mypy/issues/1289#event-638258780
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#1429https://github.com/python/mypy/pull/1429
on Apr 25, 2016https://github.com/python/mypy/issues/1289#event-640284006
JukkaLhttps://github.com/JukkaL
on Apr 25, 2016https://github.com/python/mypy/issues/1289#event-640284066
Correctly type check redefinitions in try's else clause. (#1429)https://github.com/python/mypy/commit/42b2faaa9020e95a3c3600b7bfa78410e57c1e4c
#1429https://github.com/python/mypy/pull/1429
https://docs.github.com/articles/closing-issues-via-commit-messages
42b2faahttps://github.com/python/mypy/commit/42b2faaa9020e95a3c3600b7bfa78410e57c1e4c
https://github.com/rwbarton
rwbartonhttps://github.com/rwbarton
on Jun 26, 2016https://github.com/python/mypy/issues/1289#issuecomment-228579671
#1731https://github.com/python/mypy/pull/1731
rwbartonhttps://github.com/rwbarton
on Jun 26, 2016https://github.com/python/mypy/issues/1289#event-704149845
rwbartonhttps://github.com/rwbarton
rwbartonhttps://github.com/rwbarton
gvanrossumhttps://github.com/gvanrossum
on Jun 26, 2016https://github.com/python/mypy/issues/1289#event-704149985
rwbartonhttps://github.com/rwbarton
on Jun 29, 2016https://github.com/python/mypy/issues/1289#event-707157715
Process try statements in top-to-bottom orderhttps://github.com/rwbarton/mypy/commit/b68f747c93f41be39b5c0b9e2ab4ebe0b9df5a26
https://docs.github.com/articles/closing-issues-via-commit-messages
b68f747https://github.com/rwbarton/mypy/commit/b68f747c93f41be39b5c0b9e2ab4ebe0b9df5a26
Process try statements in top-to-bottom orderhttps://github.com/rwbarton/mypy/commit/6c7ceb0666d0ae8fd08ea7a271f3fe45a20dd84b
https://docs.github.com/articles/closing-issues-via-commit-messages
6c7ceb0https://github.com/rwbarton/mypy/commit/6c7ceb0666d0ae8fd08ea7a271f3fe45a20dd84b
gnpricehttps://github.com/gnprice
on Jul 7, 2016https://github.com/python/mypy/issues/1289#event-716367889
https://github.com/gnprice
gnpricehttps://github.com/gnprice
on Jul 7, 2016https://github.com/python/mypy/issues/1289#issuecomment-231223373
@rwbartonhttps://github.com/rwbarton
#1731https://github.com/python/mypy/pull/1731
https://github.com/rwbarton
rwbartonhttps://github.com/rwbarton
on Jul 7, 2016https://github.com/python/mypy/issues/1289#issuecomment-231224230
#1748https://github.com/python/mypy/pull/1748
rwbartonhttps://github.com/rwbarton
on Oct 7, 2016https://github.com/python/mypy/issues/1289#event-815706780
Process try statements in top-to-bottom orderhttps://github.com/rwbarton/mypy/commit/8d7fef19cb0823c6588d5543ea54e83593c8f75f
https://docs.github.com/articles/closing-issues-via-commit-messages
8d7fef1https://github.com/rwbarton/mypy/commit/8d7fef19cb0823c6588d5543ea54e83593c8f75f
Process try statements in top-to-bottom orderhttps://github.com/rwbarton/mypy/commit/4ed33ee59402a14c45ff440f1236eefa363ae33d
https://docs.github.com/articles/closing-issues-via-commit-messages
4ed33eehttps://github.com/rwbarton/mypy/commit/4ed33ee59402a14c45ff440f1236eefa363ae33d
Process try statements in top-to-bottom orderhttps://github.com/rwbarton/mypy/commit/4388a8145eea27692a0884c7716b919aafe85f69
https://docs.github.com/articles/closing-issues-via-commit-messages
4388a81https://github.com/rwbarton/mypy/commit/4388a8145eea27692a0884c7716b919aafe85f69
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
3b92e79https://github.com/python/mypy/commit/3b92e790e958f20b4630b434659d736a4fca545b
on Oct 18, 2016https://github.com/python/mypy/issues/1289#event-827887920
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/1289
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/1289
rwbartonhttps://github.com/rwbarton
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%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.