Title: "Cannot determine type" on innocent but import-cycled code · Issue #2015 · python/mypy · GitHub
Open Graph Title: "Cannot determine type" on innocent but import-cycled code · Issue #2015 · python/mypy
X Title: "Cannot determine type" on innocent but import-cycled code · Issue #2015 · python/mypy
Description: The following code is perfectly well-typed, but -- depending on the order files are passed to mypy -- gives a cryptic error message: $ head * ==> part1.py <== from part3 import part3_thing class FirstThing: pass ==> part2.py <== from par...
Open Graph Description: The following code is perfectly well-typed, but -- depending on the order files are passed to mypy -- gives a cryptic error message: $ head * ==> part1.py <== from part3 import part3_thing class Fi...
X Description: The following code is perfectly well-typed, but -- depending on the order files are passed to mypy -- gives a cryptic error message: $ head * ==> part1.py <== from part3 import part3_thing cl...
Opengraph URL: https://github.com/python/mypy/issues/2015
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Cannot determine type\" on innocent but import-cycled code","articleBody":"The following code is perfectly well-typed, but -- depending on the order files are passed to `mypy` -- gives a cryptic error message:\n\n```\n$ head *\n==> part1.py \u003c==\nfrom part3 import part3_thing\nclass FirstThing: pass\n\n==> part2.py \u003c==\nfrom part4 import part4_thing\n\nimport socket\nThing = socket.socket\n\n==> part3.py \u003c==\nfrom part2 import Thing\ndef part3_thing(x, *y): pass\n_thing = Thing()\n\n==> part4.py \u003c==\nMYPY = False\nif MYPY:\n from part1 import FirstThing\npart4_thing = 1\n```\n\nOn running `mypy part[1234].py`, we get the result\n\n```\npart3.py:3: error: Cannot determine type of 'Thing'\n```\n\nThe import cycle seems to be essential. The result is also sensitive to order -- for example, `mypy part{1,3,2,4}.py` gives no error.\n\nThe repro can probably be reduced further; for example, I suspect there's a way to see it with three files, perhaps just two.\n\nThe code above obviously looks somewhat artificial -- it's stripped down from an example in a large internal codebase at Dropbox. We've seen several different people independently run into errors that look much like this in different parts of the same codebase, which has a number of import cycles, and I suspect the same thing is likely to happen in other large import-cycled codebases elsewhere. It'd be valuable to understand just what's going on here.\n\nAt a minimum, we should give a clear error message -- this one is pretty unhelpful for the user. Better yet we should fix the issue :), but import cycles have been tricky for us before so that might be difficult. If we can't immediately fix it, though, it'd be helpful even just to know what the obstacle is in this case.\n","author":{"url":"https://github.com/gnprice","@type":"Person","name":"gnprice"},"datePublished":"2016-08-12T02:32:20Z","url":"https://github.com/python/mypy/issues/2015"}
| 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:10e87321-6dbd-7382-bcdc-b2ada410106c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9984:4D728:296F4AA:362ED70:6B00088A |
| html-safe-nonce | 4f7951894e55feee47de55dcd4498f6d1ba7e384de4c2d20028f507c4954a91e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTg0OjRENzI4OjI5NkY0QUE6MzYyRUQ3MDo2QjAwMDg4QSIsInZpc2l0b3JfaWQiOiI1NTQxNDkyMjc5MjQ1NTU5MTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | beb5fc8ba465d6b4e07509d8f2efa147b9aa24f622fef208b35ece5bbd4ebcad |
| hovercard-subject-tag | issue:170787848 |
| 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/2015/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f49b006b2a300a26de05b60dd454406f9d140ca287b49768484eab29a028ca32/python/mypy/issues/2015 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f49b006b2a300a26de05b60dd454406f9d140ca287b49768484eab29a028ca32/python/mypy/issues/2015 |
| og:image:alt | The following code is perfectly well-typed, but -- depending on the order files are passed to mypy -- gives a cryptic error message: $ head * ==> part1.py <== from part3 import part3_thing class Fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gnprice |
| 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:
Viewport: width=device-width