Title: Crash when class defined in method used for instance variable's type · Issue #2559 · python/mypy · GitHub
Open Graph Title: Crash when class defined in method used for instance variable's type · Issue #2559 · python/mypy
X Title: Crash when class defined in method used for instance variable's type · Issue #2559 · python/mypy
Description: While thinking about #2535 I realized there's a similar case not involving NamedTuple (nor TypedDict): main.py: import crash blah # anything that triggers an error crash.py: class C: def f(self) -> None: class A: pass self.a = A() This t...
Open Graph Description: While thinking about #2535 I realized there's a similar case not involving NamedTuple (nor TypedDict): main.py: import crash blah # anything that triggers an error crash.py: class C: def f(self) ->...
X Description: While thinking about #2535 I realized there's a similar case not involving NamedTuple (nor TypedDict): main.py: import crash blah # anything that triggers an error crash.py: class C: def f(self...
Opengraph URL: https://github.com/python/mypy/issues/2559
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash when class defined in method used for instance variable's type","articleBody":"While thinking about https://github.com/python/mypy/issues/2535 I realized there's a similar case not involving NamedTuple (nor TypedDict):\r\n\r\n- main.py:\r\n```python\r\nimport crash\r\nblah # anything that triggers an error\r\n```\r\n\r\n- crash.py:\r\n```python\r\nclass C:\r\n def f(self) -> None:\r\n class A:\r\n pass\r\n self.a = A()\r\n```\r\nThis triggers a very similar crash in fixup.py when running `mypy -i main.py` **TWICE** (from a cold cache):\r\n```\r\n$ rm -rf .mypy_cache/\r\n$ mypy -i main.py \r\nmain.py:1: error: Name 'blah' is not defined\r\n$ mypy -i main.py \r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python3.6/runpy.py\", line 193, in _run_module_as_main\r\n \"__main__\", mod_spec)\r\n File \"/usr/local/lib/python3.6/runpy.py\", line 85, in _run_code\r\n exec(code, run_globals)\r\n File \"/Users/guido/src/mypy/mypy/__main__.py\", line 5, in \u003cmodule>\r\n main(None)\r\n File \"/Users/guido/src/mypy/mypy/main.py\", line 41, in main\r\n res = type_check_only(sources, bin_dir, options)\r\n File \"/Users/guido/src/mypy/mypy/main.py\", line 86, in type_check_only\r\n options=options)\r\n File \"/Users/guido/src/mypy/mypy/build.py\", line 183, in build\r\n dispatch(sources, manager)\r\n File \"/Users/guido/src/mypy/mypy/build.py\", line 1524, in dispatch\r\n process_graph(graph, manager)\r\n File \"/Users/guido/src/mypy/mypy/build.py\", line 1753, in process_graph\r\n process_fresh_scc(graph, prev_scc)\r\n File \"/Users/guido/src/mypy/mypy/build.py\", line 1822, in process_fresh_scc\r\n graph[id].fix_cross_refs()\r\n File \"/Users/guido/src/mypy/mypy/build.py\", line 1307, in fix_cross_refs\r\n fixup_module_pass_one(self.tree, self.manager.modules)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 21, in fixup_module_pass_one\r\n node_fixer.visit_symbol_table(tree.names)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 86, in visit_symbol_table\r\n self.visit_type_info(value.node)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 55, in visit_type_info\r\n self.visit_symbol_table(info.names)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 88, in visit_symbol_table\r\n value.node.accept(self)\r\n File \"/Users/guido/src/mypy/mypy/nodes.py\", line 658, in accept\r\n return visitor.visit_var(self)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 131, in visit_var\r\n v.type.accept(self.type_fixer)\r\n File \"/Users/guido/src/mypy/mypy/types.py\", line 433, in accept\r\n return visitor.visit_instance(self)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 144, in visit_instance\r\n node = lookup_qualified(self.modules, type_ref)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 234, in lookup_qualified\r\n stnode = lookup_qualified_stnode(modules, name)\r\n File \"/Users/guido/src/mypy/mypy/fixup.py\", line 245, in lookup_qualified_stnode\r\n assert '.' in head, \"Cannot find %s\" % (name,)\r\nAssertionError: Cannot find A\r\n```","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-12-12T22:15:43Z","url":"https://github.com/python/mypy/issues/2559"}
| 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:66aed9cd-2dee-d9c5-daa1-6158646b7443 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94DC:2AB36C:2B2E00:3AC548:6B006A00 |
| html-safe-nonce | 9d397b7f916c82a6ace74b2b4b318338c061cb7aea2ba66beca0541f0363eb66 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NERDOjJBQjM2QzoyQjJFMDA6M0FDNTQ4OjZCMDA2QTAwIiwidmlzaXRvcl9pZCI6Ijc1MzY2NzAzMzYzNDM4OTQ1MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fcf468c1296be2a9086f9d9846ce6ecaf4c7981a1deb8844cc400d0e444d2dbf |
| hovercard-subject-tag | issue:195101374 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/2559/issue_layout |
| twitter:image | https://opengraph.githubassets.com/985df8bed63c10f1026e5bc499826925fd0b3844a40fb4623c2f6a1c01861d26/python/mypy/issues/2559 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/985df8bed63c10f1026e5bc499826925fd0b3844a40fb4623c2f6a1c01861d26/python/mypy/issues/2559 |
| og:image:alt | While thinking about #2535 I realized there's a similar case not involving NamedTuple (nor TypedDict): main.py: import crash blah # anything that triggers an error crash.py: class C: def f(self) ->... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width