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-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:30cdf9a5-c56d-ab50-067a-ee39afabe259 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D960:37308E:274D924:339620D:6B0005FC |
| html-safe-nonce | 5395f28044bd12edb43bbd8a8a25b35843f3a4d72db9607eeece4895d2d297bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTYwOjM3MzA4RToyNzREOTI0OjMzOTYyMEQ6NkIwMDA1RkMiLCJ2aXNpdG9yX2lkIjoiNTQzNzI5NzMyNzE1MDcyODcwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 44a5225cb8dd329671d7c404559e37686cc965a2350d04a28ef01fcd13734f00 |
| hovercard-subject-tag | issue:140367368 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | ///voltron/issues_fragments/issue_layout |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/1289/issue_layout |
| twitter:image | https://opengraph.githubassets.com/83b018cf932e7869c3c278e7ac10c52d3bbad2465757f2f2fc9a5077be64e489/python/mypy/issues/1289 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/83b018cf932e7869c3c278e7ac10c52d3bbad2465757f2f2fc9a5077be64e489/python/mypy/issues/1289 |
| og:image:alt | 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 |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aiiie |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Skip to content | https://github.com/python/mypy/issues/1289#start-of-content |
| https://github.com/ |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F1289 |
| GitHubRepository hosting, code review, and collaboration | https://github.com/platform |
| CopilotAI coding agent for tasks, projects, and automated work | https://github.com/features/copilot |
| ActionsCI/CD and automation | https://github.com/features/actions |
| Code QualityQuality analysis, fixes, and enforcement | https://github.com/features/code-quality |
| CodespacesCloud development environments | https://github.com/features/codespaces |
| Code SecurityVulnerability detection and remediation | https://github.com/security/advanced-security/code-security |
| Secret ProtectionSecret scanning and leak prevention | https://github.com/security/advanced-security/secret-protection |
| All Features | https://github.com/features |
| Documentation | https://docs.github.com/en |
| Training | https://learn.github.com/skills |
| Certifications | https://learn.github.com/credentials |
| Build with Copilot | https://github.com/features/ai |
| Customize Copilot | https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview |
| Integrations | https://github.com/marketplace |
| Trending repos | https://github.com/trending |
| GitHub Sponsors | https://github.com/open-source/sponsors |
| Developer articles | https://github.com/resources/articles |
| ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place. | https://github.blog/changelog/ |
| Enterprises | https://github.com/enterprise |
| Team | https://github.com/team |
| Startups | https://github.com/enterprise/startups |
| Nonprofits | https://github.com/solutions/industry/nonprofits |
| Healthcare | https://github.com/solutions/industry/healthcare |
| Financial services | https://github.com/solutions/industry/financial-services |
| Manufacturing | https://github.com/solutions/industry/manufacturing |
| Government | https://github.com/solutions/industry/government |
| See all industries | https://github.com/solutions/industry |
| Why GitHub | https://github.com/why-github |
| Customer Stories | https://github.com/customer-stories |
| Business insights | https://github.com/solutions/executive-insights |
| Trust Center | https://github.com/trust-center |
| GitHub Advanced SecurityEnterprise-grade code security | https://github.com/security/advanced-security |
| Copilot for businessEnterprise-grade AI features | https://github.com/features/copilot/copilot-business |
| Premium SupportEnterprise-grade 24/7 support | https://github.com/enterprise/premium-support |
| Documentation | https://docs.github.com/en |
| Resource center | https://github.com/resources |
| Blog | https://github.blog/ |
| Events & webinars | https://github.com/resources/events |
| Community Forum | https://github.com/orgs/community/discussions |
| Customer Stories | https://github.com/customer-stories |
| Integrations | https://github.com/marketplace |
| Customer support | https://help.github.com/ |
| Training | https://learn.github.com/skills |
| GitHub Status | https://www.githubstatus.com/ |
| About | https://github.com/about |
| Partners | https://github.com/partners |
| Changelog | https://github.blog/changelog/ |
| GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub. | https://githubuniverse.com/ |
| Pricing | https://github.com/pricing |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F1289 |
| Sign up | https://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 |
| Reload | https://github.com/python/mypy/issues/1289 |
| Reload | https://github.com/python/mypy/issues/1289 |
| Reload | https://github.com/python/mypy/issues/1289 |
| python | https://github.com/python |
| mypy | https://github.com/python/mypy |
| Code | https://github.com/python/mypy |
| Issues2.7k (2.7k) | https://github.com/python/mypy/issues |
| Pull requests547 (547) | https://github.com/python/mypy/pulls |
| Actions | https://github.com/python/mypy/actions |
| Projects | https://github.com/python/mypy/projects |
| Wiki | https://github.com/python/mypy/wiki |
| Security and quality | https://github.com/python/mypy/security |
| Insights | https://github.com/python/mypy/insights |
| https://github.com/python/mypy |
| New issue | https://github.com/login?return_to=https://github.com/python/mypy/issues/1289 |
| New issue | https://github.com/login?return_to=https://github.com/python/mypy/issues/1289 |
| Error when checking function conditionally defined in try/except/else clause | https://github.com/python/mypy/issues/1289#top |
| https://github.com/rwbarton |
| bugmypy got something wrong | https://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22 |
| https://github.com/aiiie |
| aiiie | https://github.com/aiiie |
| on Mar 12, 2016 | https://github.com/python/mypy/issues/1289#issue-140367368 |
| gvanrossum | https://github.com/gvanrossum |
| bugmypy got something wrong | https://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22 |
| on Mar 17, 2016 | https://github.com/python/mypy/issues/1289#event-594053093 |
| https://github.com/ddfisher |
| ddfisher | https://github.com/ddfisher |
| on Mar 17, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-198081186 |
| https://github.com/gvanrossum |
| gvanrossum | https://github.com/gvanrossum |
| on Mar 17, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-198081297 |
| #1297 | https://github.com/python/mypy/issues/1297 |
| https://github.com/gvanrossum |
| gvanrossum | https://github.com/gvanrossum |
| on Mar 17, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-198081872 |
| #1297 | https://github.com/python/mypy/issues/1297 |
| gvanrossum | https://github.com/gvanrossum |
| on Mar 17, 2016 | https://github.com/python/mypy/issues/1289#event-594059739 |
| https://github.com/aiiie |
| aiiie | https://github.com/aiiie |
| on Mar 18, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-198248090 |
| https://github.com/JukkaL |
| JukkaL | https://github.com/JukkaL |
| on Mar 18, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-198353390 |
| https://github.com/JukkaL |
| JukkaL | https://github.com/JukkaL |
| on Apr 21, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-212904505 |
| gvanrossum | https://github.com/gvanrossum |
| on Apr 22, 2016 | https://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 |
| 0b5efee | https://github.com/python/mypy/commit/0b5efee728ba64d644299d35a82b6cf5ccbc8d3f |
| https://github.com/gvanrossum |
| gvanrossum | https://github.com/gvanrossum |
| on Apr 22, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-213591824 |
| @Brodie | https://github.com/Brodie |
| @jukka | https://github.com/jukka |
| gvanrossum | https://github.com/gvanrossum |
| on Apr 22, 2016 | https://github.com/python/mypy/issues/1289#event-638258780 |
| JukkaL | https://github.com/JukkaL |
| completed | https://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted |
| #1429 | https://github.com/python/mypy/pull/1429 |
| on Apr 25, 2016 | https://github.com/python/mypy/issues/1289#event-640284006 |
| JukkaL | https://github.com/JukkaL |
| on Apr 25, 2016 | https://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 |
| #1429 | https://github.com/python/mypy/pull/1429 |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 42b2faa | https://github.com/python/mypy/commit/42b2faaa9020e95a3c3600b7bfa78410e57c1e4c |
| https://github.com/rwbarton |
| rwbarton | https://github.com/rwbarton |
| on Jun 26, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-228579671 |
| #1731 | https://github.com/python/mypy/pull/1731 |
| rwbarton | https://github.com/rwbarton |
| on Jun 26, 2016 | https://github.com/python/mypy/issues/1289#event-704149845 |
| rwbarton | https://github.com/rwbarton |
| rwbarton | https://github.com/rwbarton |
| gvanrossum | https://github.com/gvanrossum |
| on Jun 26, 2016 | https://github.com/python/mypy/issues/1289#event-704149985 |
| rwbarton | https://github.com/rwbarton |
| on Jun 29, 2016 | https://github.com/python/mypy/issues/1289#event-707157715 |
| Process try statements in top-to-bottom order | https://github.com/rwbarton/mypy/commit/b68f747c93f41be39b5c0b9e2ab4ebe0b9df5a26 |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| b68f747 | https://github.com/rwbarton/mypy/commit/b68f747c93f41be39b5c0b9e2ab4ebe0b9df5a26 |
| Process try statements in top-to-bottom order | https://github.com/rwbarton/mypy/commit/6c7ceb0666d0ae8fd08ea7a271f3fe45a20dd84b |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 6c7ceb0 | https://github.com/rwbarton/mypy/commit/6c7ceb0666d0ae8fd08ea7a271f3fe45a20dd84b |
| gnprice | https://github.com/gnprice |
| on Jul 7, 2016 | https://github.com/python/mypy/issues/1289#event-716367889 |
| https://github.com/gnprice |
| gnprice | https://github.com/gnprice |
| on Jul 7, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-231223373 |
| @rwbarton | https://github.com/rwbarton |
| #1731 | https://github.com/python/mypy/pull/1731 |
| https://github.com/rwbarton |
| rwbarton | https://github.com/rwbarton |
| on Jul 7, 2016 | https://github.com/python/mypy/issues/1289#issuecomment-231224230 |
| #1748 | https://github.com/python/mypy/pull/1748 |
| rwbarton | https://github.com/rwbarton |
| on Oct 7, 2016 | https://github.com/python/mypy/issues/1289#event-815706780 |
| Process try statements in top-to-bottom order | https://github.com/rwbarton/mypy/commit/8d7fef19cb0823c6588d5543ea54e83593c8f75f |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 8d7fef1 | https://github.com/rwbarton/mypy/commit/8d7fef19cb0823c6588d5543ea54e83593c8f75f |
| Process try statements in top-to-bottom order | https://github.com/rwbarton/mypy/commit/4ed33ee59402a14c45ff440f1236eefa363ae33d |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 4ed33ee | https://github.com/rwbarton/mypy/commit/4ed33ee59402a14c45ff440f1236eefa363ae33d |
| Process try statements in top-to-bottom order | https://github.com/rwbarton/mypy/commit/4388a8145eea27692a0884c7716b919aafe85f69 |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 4388a81 | https://github.com/rwbarton/mypy/commit/4388a8145eea27692a0884c7716b919aafe85f69 |
| JukkaL | https://github.com/JukkaL |
| completed | https://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted |
| 3b92e79 | https://github.com/python/mypy/commit/3b92e790e958f20b4630b434659d736a4fca545b |
| on Oct 18, 2016 | https://github.com/python/mypy/issues/1289#event-827887920 |
| Sign up for free | https://github.com/signup?return_to=https://github.com/python/mypy/issues/1289 |
| Sign in to comment | https://github.com/login?return_to=https://github.com/python/mypy/issues/1289 |
| rwbarton | https://github.com/rwbarton |
| bugmypy got something wrong | https://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22 |
|
| https://github.com |
| Terms | https://docs.github.com/site-policy/github-terms/github-terms-of-service |
| Privacy | https://docs.github.com/site-policy/privacy-policies/github-privacy-statement |
| Security | https://github.com/security |
| Status | https://www.githubstatus.com/ |
| Community | https://github.community/ |
| Docs | https://docs.github.com/ |
| Contact | https://support.github.com?tags=dotcom-footer |
Viewport: width=device-width
URLs of crawlers that visited me.