Title: Importing types from namespace packages emits false positives without `from ... import ...` · Issue #5758 · python/mypy · GitHub
Open Graph Title: Importing types from namespace packages emits false positives without `from ... import ...` · Issue #5758 · python/mypy
X Title: Importing types from namespace packages emits false positives without `from ... import ...` · Issue #5758 · python/mypy
Description: Importing type hints from namespace packages only works when using the from ... import ... form. Using the --namespace-packages flag works properly when the typedpkg_namespace-alpha is not installed but mypy is executed from the director...
Open Graph Description: Importing type hints from namespace packages only works when using the from ... import ... form. Using the --namespace-packages flag works properly when the typedpkg_namespace-alpha is not installe...
X Description: Importing type hints from namespace packages only works when using the from ... import ... form. Using the --namespace-packages flag works properly when the typedpkg_namespace-alpha is not installe...
Opengraph URL: https://github.com/python/mypy/issues/5758
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Importing types from namespace packages emits false positives without `from ... import ...`","articleBody":"Importing type hints from namespace packages only works when using the `from ... import ...` form.\r\n\r\nUsing the `--namespace-packages` flag works properly when the `typedpkg_namespace-alpha` is not installed but `mypy` is executed from the directory containing the package contents (as expected) but only for imports using the `from ... import ...` style. `import ...` does not work as expected. Likewise the same is true without the `--namespace-packages` flag if `typedpkg_namespace-alpha` is installed.\r\n\r\nSpecifically, the type hints are correctly imported but a false positive error message is still emitted of `Cannot find module named 'typedpkg_namespace'`.\r\n\r\n# Repro steps\r\n- Virtual env state\r\n```\r\n$ pip list\r\nPackage Version\r\n--------------- --------------------------------------------------\r\nmypy 0.640+dev.e12be3ba9e6be3e9242e3a81ffaa9b3a136876fe\r\nmypy-extensions 0.4.1\r\npip 18.1\r\nsetuptools 40.4.3\r\ntyped-ast 1.1.0\r\n```\r\n- Repro file structure\r\n```\r\n$ find . \\( -path ./.mypy_cache -o -path ./venv \\) -prune -o -print\r\n.\r\n./typedpkg_namespace\r\n./typedpkg_namespace/alpha\r\n./typedpkg_namespace/alpha/__init__.py\r\n./typedpkg_namespace/alpha/py.typed\r\n./typedpkg_namespace/alpha/alpha_module.py\r\n./not_from_imp.py\r\n./from_imp.py\r\n./setup.py\r\n```\r\n- Repro files\r\n - `setup.py`\r\n ```\r\n setup(\r\n name='typedpkg_namespace.alpha',\r\n version='1.0.0',\r\n packages=find_namespace_packages(),\r\n namespace_packages=['typedpkg_namespace'],\r\n zip_safe=False,\r\n package_data={'typedpkg_namespace.alpha': ['py.typed']}\r\n )\r\n ```\r\n - `typedpkg_namespace/alpha/alpha_module.py`\r\n ```\r\n def alpha_func(a: bool) -> bool:\r\n return not a\r\n ```\r\n - `from_imp.py`\r\n ```\r\n from typedpkg_namespace.alpha.alpha_module import alpha_func\r\n alpha_func(False)\r\n alpha_func(2)\r\n ```\r\n - `not_from_imp.py`\r\n ```\r\n import typedpkg_namespace.alpha.alpha_module as am; alpha_func = am.alpha_func\r\n alpha_func(False)\r\n alpha_func(2)\r\n ```\r\n - `typedpkg_namespace/alpha/__init__.py` and `typedpkg_namespace/alpha/py.typed` are empty\r\n \r\n# Repro Example\r\n- using `--namespace-packages`\r\n```\r\n$ mypy from_imp.py --namespace-packages\r\nfrom_imp.py:3: error: Argument 1 to \"alpha_func\" has incompatible type \"int\"; expected \"bool\"\r\n\r\n$ mypy not_from_imp.py --namespace-packages\r\nnot_from_imp.py:1: error: Cannot find module named 'typedpkg_namespace'\r\nnot_from_imp.py:1: note: (Perhaps setting MYPYPATH or using the \"--ignore-missing-imports\" flag would help)\r\nnot_from_imp.py:3: error: Argument 1 has incompatible type \"int\"; expected \"bool\"\r\n```\r\n- using installed package\r\n```\r\n$ pip install .\r\nLooking in indexes: http://artifactory.factset.com/artifactory/api/pypi/python/simple/\r\nProcessing /home/user/cphilip/side_projects/test_namespace/typedpkg_namespace-alpha\r\nInstalling collected packages: typedpkg-namespace.alpha\r\n Running setup.py install for typedpkg-namespace.alpha ... done\r\nSuccessfully installed typedpkg-namespace.alpha-1.0.0\r\n\r\n$ pip list\r\nPackage Version\r\n------------------------ --------------------------------------------------\r\nmypy 0.640+dev.e12be3ba9e6be3e9242e3a81ffaa9b3a136876fe\r\nmypy-extensions 0.4.1\r\npip 18.1\r\nsetuptools 40.4.3\r\ntyped-ast 1.1.0\r\ntypedpkg-namespace.alpha 1.0.0\r\n\r\n$ mypy from_imp.py\r\nfrom_imp.py:3: error: Argument 1 to \"alpha_func\" has incompatible type \"int\"; expected \"bool\"\r\n\r\n$ mypy not_from_imp.py\r\nnot_from_imp.py:1: error: Cannot find module named 'typedpkg_namespace'\r\nnot_from_imp.py:1: note: (Perhaps setting MYPYPATH or using the \"--ignore-missing-imports\" flag would help)\r\nnot_from_imp.py:3: error: Argument 1 has incompatible type \"int\"; expected \"bool\"\r\n```","author":{"url":"https://github.com/chrisphilip322","@type":"Person","name":"chrisphilip322"},"datePublished":"2018-10-09T14:36:21Z","url":"https://github.com/python/mypy/issues/5758"}
| 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:8b005ced-4139-1c4f-8b1e-990972e5eb3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 824C:16AD57:87AF0:BE0F2:6B004ED6 |
| html-safe-nonce | 7d7f913053b1618c98ad71da134cdf048776e84cc9d7995c667466725048cb92 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjRDOjE2QUQ1Nzo4N0FGMDpCRTBGMjo2QjAwNEVENiIsInZpc2l0b3JfaWQiOiI5MTA5NDk3NDgzMzc3MDA0MjQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 006e365ebb820dc69c4d76f6f753595be216f87d5b8f2a367f43d0d1782bcdd2 |
| hovercard-subject-tag | issue:368243656 |
| 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/5758/issue_layout |
| twitter:image | https://opengraph.githubassets.com/21c51eaddfde1d581c4757a0292fce2ea8079c855487a4b67ddbcb716580e01b/python/mypy/issues/5758 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/21c51eaddfde1d581c4757a0292fce2ea8079c855487a4b67ddbcb716580e01b/python/mypy/issues/5758 |
| og:image:alt | Importing type hints from namespace packages only works when using the from ... import ... form. Using the --namespace-packages flag works properly when the typedpkg_namespace-alpha is not installe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chrisphilip322 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width