Title: Relative imports from within the same package lead to "no type hints or stubs" error · Issue #8726 · python/mypy · GitHub
Open Graph Title: Relative imports from within the same package lead to "no type hints or stubs" error · Issue #8726 · python/mypy
X Title: Relative imports from within the same package lead to "no type hints or stubs" error · Issue #8726 · python/mypy
Description: Hi, I have a problem with mypy and handling of imports. Basically, I have a Python package with several modules which import other modules of the package. When I run mypy (version 0.770) on the files, I get this error: error: Skipping an...
Open Graph Description: Hi, I have a problem with mypy and handling of imports. Basically, I have a Python package with several modules which import other modules of the package. When I run mypy (version 0.770) on the fil...
X Description: Hi, I have a problem with mypy and handling of imports. Basically, I have a Python package with several modules which import other modules of the package. When I run mypy (version 0.770) on the fil...
Opengraph URL: https://github.com/python/mypy/issues/8726
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Relative imports from within the same package lead to \"no type hints or stubs\" error","articleBody":"Hi,\r\n\r\nI have a problem with mypy and handling of imports. Basically, I have a Python package with several modules which import other modules of the package. When I run `mypy` (version 0.770) on the files, I get this error:\r\n`error: Skipping analyzing '.file2': found module but no type hints or library stubs`\r\n\r\nHowever, I don't understand that error message because (in this example) `file2` does contain type hints. \r\nFor the purpose of this issue, I have created a minimal reproducer. I have two files `file1` and `file2` which both define a class. The class in `file1` (`Example1`) has a method which uses the class from `file2` (`Example2`), thus `file1` imports `file2` with a relative import (`from .file2 import Example2`). This is the full code:\r\n\r\n- `file1.py`\r\n```python\r\nfrom .file2 import Example2\r\n\r\nclass Example1:\r\n def __init__(self, value: float) -> None:\r\n self.value = value\r\n\r\n def add(self, other: Example2) -> None:\r\n self.value += other.value\r\n```\r\n- `file2.py`\r\n```python\r\nclass Example2:\r\n def __init__(self, value: float) -> None:\r\n self.value = value\r\n```\r\n\r\nWhen I run `mypy file1.py file2.py`, I am receiving the error mentioned above:\r\n```\r\nfile1.py:1: error: Skipping analyzing '.file2': found module but no type hints or library stubs\r\nfile1.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports\r\n```\r\nNow I did visit that recommended link in the documentation but I couldn't figure out how to solve my problem. \r\n\r\nHowever, one thing that worked was to turn the relative into a global import, i.e. to write `from file2 import Example2`. However, I would like to avoid that because in my package I would prefer to use relative imports for ease of readability of the code (amongst others). Also, the error message does not seem to make sense to me because `file2.py` does contain type annotations.\r\n\r\nApologies for posting this because it seems like a basic thing, but I couldn't figure it out with the documentation or by browsing the issues here. \r\nIt would be great if someone could explain how to do this properly or point me to a documentation of the solution.\r\nThanks a lot.\r\n\r\n(Python version if 3.8.2).","author":{"url":"https://github.com/mschmidt87","@type":"Person","name":"mschmidt87"},"datePublished":"2020-04-26T04:34:50Z","url":"https://github.com/python/mypy/issues/8726"}
| 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:f8f4ffeb-425f-73b6-c5cf-0fe93c127ae8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A856:1BCD46:4B2C91:64E1E4:6B002F0C |
| html-safe-nonce | c4e265a19b2d0eb41295663199ee119ca3268f2ec80c05454713bb164d8f643e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODU2OjFCQ0Q0Njo0QjJDOTE6NjRFMUU0OjZCMDAyRjBDIiwidmlzaXRvcl9pZCI6IjE5Njc4MDg2NDA3NjkzMzkxNDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8499ddf036e2ffe7dd18e498ef216067c38267c7c1af1c43b1eb1ec86dff0c3b |
| hovercard-subject-tag | issue:606916557 |
| 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/8726/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5750d8301d92ffcf2d8f1f8384e69869cd4e64e884719573e5a4f9276fbf5d70/python/mypy/issues/8726 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5750d8301d92ffcf2d8f1f8384e69869cd4e64e884719573e5a4f9276fbf5d70/python/mypy/issues/8726 |
| og:image:alt | Hi, I have a problem with mypy and handling of imports. Basically, I have a Python package with several modules which import other modules of the package. When I run mypy (version 0.770) on the fil... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mschmidt87 |
| 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