Title: Legal Python circular imports result in loss of type information · Issue #4429 · python/mypy · GitHub
Open Graph Title: Legal Python circular imports result in loss of type information · Issue #4429 · python/mypy
X Title: Legal Python circular imports result in loss of type information · Issue #4429 · python/mypy
Description: Example: test/__init__.py: import typing from . import a from . import b if typing.TYPE_CHECKING: reveal_type(a.foo()) test/a.py: import test def foo() -> int: return test.b.x test/b.py: import test import typing x = 42 def run() -> int:...
Open Graph Description: Example: test/__init__.py: import typing from . import a from . import b if typing.TYPE_CHECKING: reveal_type(a.foo()) test/a.py: import test def foo() -> int: return test.b.x test/b.py: import tes...
X Description: Example: test/__init__.py: import typing from . import a from . import b if typing.TYPE_CHECKING: reveal_type(a.foo()) test/a.py: import test def foo() -> int: return test.b.x test/b.py: import ...
Opengraph URL: https://github.com/python/mypy/issues/4429
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Legal Python circular imports result in loss of type information","articleBody":"Example:\r\n\r\n`test/__init__.py`:\r\n```python\r\nimport typing\r\n\r\nfrom . import a\r\nfrom . import b\r\n\r\nif typing.TYPE_CHECKING:\r\n reveal_type(a.foo())\r\n```\r\n\r\n`test/a.py`:\r\n```python\r\nimport test\r\n\r\ndef foo() -> int:\r\n return test.b.x\r\n```\r\n\r\n`test/b.py`:\r\n```python\r\nimport test\r\nimport typing\r\nx = 42\r\n\r\ndef run() -> int:\r\n if typing.TYPE_CHECKING:\r\n reveal_type(test.a.foo())\r\n return test.a.foo()\r\n```\r\n\r\n`test/__main__.py`\r\n```python\r\nimport test\r\n\r\nprint(test.b.run())\r\n```\r\n\r\nPython will execute the above code just fine:\r\n\r\n```bash\r\n$ python3 -m test\r\n42\r\n```\r\n\r\nBut `mypy` loses the type information for `test.a` in the context of `b.py`\r\n```bash\r\n$ mypy test/__init__.py test/a.py test/b.py\r\ntest/b.py:7: error: Revealed type is 'Any'\r\ntest/__init__.py:7: error: Revealed type is 'builtins.int'\r\n```\r\n\r\nWhat's odd is if I reorder the files to explicitly pass in `b.py` first, things work -\r\n\r\n```bash\r\n$ mypy test/b.py test/a.py test/__init__.py\r\ntest/__init__.py:7: error: Revealed type is 'builtins.int'\r\ntest/b.py:7: error: Revealed type is 'builtins.int'\r\n```","author":{"url":"https://github.com/rowillia","@type":"Person","name":"rowillia"},"datePublished":"2018-01-03T23:39:58Z","url":"https://github.com/python/mypy/issues/4429"}
| 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:3a99206f-ac48-eb2e-0da1-101b902491e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA2A:1E3154:A70C5E:DF1D17:6B0046CC |
| html-safe-nonce | 7f88ed6a869abb3cb39447a55e1f2fde14571315a6b70e8f841558af4a732f11 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTJBOjFFMzE1NDpBNzBDNUU6REYxRDE3OjZCMDA0NkNDIiwidmlzaXRvcl9pZCI6IjgxMzI5Mjc4MTY5ODAyNTIzNjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5b5f7c992d75541f1b52453a6e9742f36ae687aa5eac80e3b5d4dc1c0d5ae416 |
| hovercard-subject-tag | issue:285842142 |
| 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/4429/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6fd8d5b34e9f809d4cad56d2b064b3caf757f5fbffbd009c5f76be0e1abe4a5e/python/mypy/issues/4429 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6fd8d5b34e9f809d4cad56d2b064b3caf757f5fbffbd009c5f76be0e1abe4a5e/python/mypy/issues/4429 |
| og:image:alt | Example: test/__init__.py: import typing from . import a from . import b if typing.TYPE_CHECKING: reveal_type(a.foo()) test/a.py: import test def foo() -> int: return test.b.x test/b.py: import tes... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rowillia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width