Title: Duplicate module error with stub files · Issue #17362 · python/mypy · GitHub
Open Graph Title: Duplicate module error with stub files · Issue #17362 · python/mypy
X Title: Duplicate module error with stub files · Issue #17362 · python/mypy
Description: Bug Report When a project contains an untyped source (.py) file and a corresponding stub (.pyi) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via the command line. Consider a simple package foo with...
Open Graph Description: Bug Report When a project contains an untyped source (.py) file and a corresponding stub (.pyi) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via the command ...
X Description: Bug Report When a project contains an untyped source (.py) file and a corresponding stub (.pyi) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via th...
Opengraph URL: https://github.com/python/mypy/issues/17362
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Duplicate module error with stub files","articleBody":"**Bug Report**\r\n\r\nWhen a project contains an untyped source (`.py`) file and a corresponding stub (`.pyi`) file, Mypy may emit \"Duplicate module\" errors depending on how the files were passed via the command line.\r\n\r\nConsider a simple package `foo` with this project layout:\r\n\r\n```\r\nfoo\r\n├── __init__.py\r\n└── __init__.pyi\r\n```\r\n\r\nMypy runs without error if I pass it the `foo` directory as argument\r\n\r\n```console\r\n$ mypy foo\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\nBut if I pass the directory contents as separate arguments, Mypy emits an error due to the two files having the same module name\r\n\r\n```console\r\n$ mypy foo/*\r\nfoo/__init__.pyi: error: Duplicate module named \"foo\" (also at \"foo/__init__.py\")\r\nfoo/__init__.pyi: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info\r\nfoo/__init__.pyi: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH\r\nFound 1 error in 1 file (errors prevented further checking)\r\n```\r\n\r\nIs this the intended behavior?\r\n\r\n**To Reproduce**\r\n\r\n(see above)\r\n\r\n**Expected Behavior**\r\n\r\nI expected that the `.pyi` file would supersede the `.py` file in both cases above (regardless of how the files were passed from the command line), or perhaps that Mypy would process the files independently in the second case and ignore naming collisions.\r\n\r\nIn my actual use case, I am running Mypy via a [pre-commit](https://pre-commit.com/) hook, which always passes individual files as separate arguments. The addition of a stub file caused Mypy to raise the \"Duplicate module\" error. I was able to work around the error by configuring pre-commit to exclude the original `.py` file, but this seems like a pretty typical use case that Mypy might want to support.\r\n\r\nhttps://github.com/isce-framework/snaphu-py/pull/68\r\n\r\n**Actual Behavior**\r\n\r\n(see above)\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.10.0\r\n- Mypy command-line flags: none\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: 3.12.3\r\n","author":{"url":"https://github.com/gmgunter","@type":"Person","name":"gmgunter"},"datePublished":"2024-06-11T05:58:56Z","url":"https://github.com/python/mypy/issues/17362"}
| 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:8e2bdbe8-2350-8c36-4a4c-e7e1a0929085 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A494:1A7566:C135B1:1027A63:6B004E6E |
| html-safe-nonce | 618eae0747a22256053ca0aab4832135cf1a40d128ef081a5452751f5bc09b8a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDk0OjFBNzU2NjpDMTM1QjE6MTAyN0E2Mzo2QjAwNEU2RSIsInZpc2l0b3JfaWQiOiI4MTc5NjI2Mjg3NzIwMDU4NDc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a4ab61168bcf510afa24acbca87eac7a3963a0e7f63d40975e7f7fc854790ecd |
| hovercard-subject-tag | issue:2345464607 |
| 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/17362/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a04e741a3c2f93e4943ee826e38a394e6c708743300d4ef0f325d71f9525e993/python/mypy/issues/17362 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a04e741a3c2f93e4943ee826e38a394e6c708743300d4ef0f325d71f9525e993/python/mypy/issues/17362 |
| og:image:alt | Bug Report When a project contains an untyped source (.py) file and a corresponding stub (.pyi) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via the command ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gmgunter |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width