-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[release 0.780] Source file found twice under different module names error. #8944
Comments
How are you invoking mypy, and what does your directory structure look like? Also, please share your config file/command line flags if possible. |
Directory Structure:
Invocation: Config
|
We're running into the same problem. I thought it might have been caused by mypy-protobuf, but it doesn't look like the OP was using that. I posted some details in the above issue, but here are some more: Error message:
Directory structure (all files outside of
mypy.ini
mypy invocation (run from the root of the repository):
|
I ran into this too, even though I'm not setting
The config file doesn't have options that should be relevant, and the same error appears if I don't pass any config file. |
Hm, then perhaps this is a regression after all? I think this definitely merits further investigation. |
@ayushr2 If @roitk You have @JelleZijlstra Your issue might be different. Can you give a full example, including all relevant source files? |
I suspect Jelle's issue is also a spurious Line 101 in 3adb2e9
|
@hauntsaninja is correct. The directory structure in my example is as follows:
(plus numerous other files not relevant here). If I remove the outer |
I'm hitting this. It happens because I have to specify all the subfolders explicitly in order to get mypy to process them, since it doesn't process folders recursively (contrary to what its documentation says). e.g.
If I turn off I've noticed for some time that it was double-reporting everything, implying it's been processing things twice, but it didn't originally do that - I'm not certain, but I think this was a mypy change, not something I did. Alas I don't know which version of mypy introduced that duplicate processing. |
mypy should recursively process your directories, and in fact it definitely is doing that to some extent, since it's clearly finding |
I found I had this problem when upgrading from 0.770 to 0.780 in multiple projects. When I removed MYPY_PATH from the environment variable and defining mypy_path in mypy.ini as a gobal fixed the issue. |
@wadetregaskis-linkedin You might be hitting #5759. Namespace package support is currently incomplete but a major update to namespace packages is being planned (#8584). @httpstergeek It would be helpful if you can provide a simplified but complete example which reproduces your issue. It seems that things are working unexpectedly in some specific scenarios that we don't yet fully understand. |
@hauntsaninja, no, it definitely doesn't process directories recursively unless they're modules (i.e. it gets 'src' and all its subfolders, because 'src' has a 'foo' subfolder with an The duplicates only arise when I specify all the subfolders explicitly, and only for the subfolders I specify (since otherwise mypy ignores them). IIRC it also reports things twice from not just the 'test' folder but also 'src', implying that somehow merely mentioning both, and having the files in 'test' import those from 'src', somehow causes it to do a redundant pass. |
@JukkaL I also hit this issue after upgrade. I think it is the same issue reported here. Here is a minimal recreate (using CentOS 7): mkdir -p lib/dir1/dir2/dir3/dir4 With mypy 0.781: With mypy 0.770: |
I have the same issue, but just a single init.py in our main directory. If I remove the init.py it works fine. |
The same happens for https://github.com/typeddjango/djangorestframework-stubs Output:
When I delete |
I experienced the opposite – adding an mypy app/mailers app/models app/services utils We are gradually adding typechecks to the project, and the next step was to add the
At first I tried moving Edit: this must be #5759, as we use mypy with |
I am hitting this too today (
As per @richtong 's suggestion above, removing the Unfortunately, that Aside: what's interesting is this error is only triggered for one source file, even though this error could exist in many places within the library. I am coming here for one question and one suggestion:
|
@jamesbraza could you also share the command you use to run mypy? |
@killthekitten yeah I use the
I noticed that if I get rid of the
In my opinion, the more desirable workaround would be to make this error message suppressible. Update: I am no longer hitting this error, as it turns out (found out through #9341) I was improperly invoking Perhaps that might be the root of your problem @ayushr2 ? |
ALL: The solution is to use |
- Remove __init__.py for MyPy 0.800 Not sure why this just showed up now, as others hit it with 0.780. python/mypy#8944 - Use the /usr/local/bin path to MyPy. pip3 is confusing.
Problem is back in 0.80. If I pin pypy to 0.782 the error is gone. Unfortunately, the code in question has a complex Is there a simple way to suppress this particular error? Thanks! |
I experienced the same issue in a mono-repo with namespace packages, but passing |
Same issue of python/mypy#8944 (comment)
Same issue of python/mypy#8944 (comment)
Specifying the name of the package (full namespace) instead of the path to the directory, resolved the issue for me with mypy v0.800.
Not ideal, but a temporary workaround. |
@JukkaL Than should we create |
@JukkaL I am facing the same error. I have mypy.ini in the root directory but it must have mypy = 0.812 |
The solution is described in the following issue python/mypy#8944 (comment) Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
After seeing the same or similar issue with namespace packages with All good setuplayout:
setup.cfg:
in project root:
Error casesNo
No
As @jakob-keller already pointed out, the |
I'm seeing this error because I have a module
(Note that mypy was straight up crashing before this, because internally it does This error occurs when you have any module in the current directory that is named the same as a Python builtin module, such as I tried the previous commenter's suggestion to use
but that spits out a slew of errors |
These docs explain the tools you have to solve your problem: https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules |
I am facing the same issue (v0.812). However I don't see how the "-p" option can be provided if I am using a mypy.ini file. The "files=" option provides the directories to inspect, but it does not allow for a packages-related configuration item. In my case, removing a (useful) init.py file did the trick. However, that file being necessary (as it used in a typing_stubs folder, over the structure of which I have no control), I have to put it back and figure out another solution... |
Answering my own previous comment: there is no such equivalent. |
Idk if I'm missing something obvious, but mypy refuses to even try to type-check that way:
This answer suggests one have to create a |
For most people encountering this issue, your problems are likely solvable by reading https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules or https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-exclude https://gitter.im/python/typing is a good place to get help and you can always open a new issue. |
Maintainer edit from 2023
Most likely, you want to run mypy via
mypy -p package
instead ofmypy package/
.To investigate your situation further, see https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules
I don't recommend reading this thread, there's a lot of out of date information in here.
After yesterday's release 0.780, our CI starting failing with the message
Source file found twice under different module names: 'grader.testlib.framework' and 'testlib.framework'
but we only have one file namedframework.py
ingrader/testlib/framework.py
. This error does not show up in version 0.770.The text was updated successfully, but these errors were encountered: