-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange name substitution on upgrading to >= 0.900 from 0.812 #10661
Comments
Thank you for giving a detailed bug report. My guess is there is an issue with some kind of import cycle confusing the analyzer, but that wouldn't make sense why it would think the classes contain themselves... Could you check if you can get attributes off of the replaced types? Also perhaps try using reveal_type() before? |
I added in
and in
Strangely, mypy reveals each line twice: once correctly, and once incorrectly:
I'm not sure what you mean by that |
Interesting that one case has lowercase |
Maybe his file system is case insensitive, but some functions are normalizing filenames? |
This is running in CentOS, so the file system is definitely case sensitive |
And just to make sure, you don't have both a |
that is correct! |
Strange, then I wonder where mypy gets the uppercase filenames from. If your filesystem isn't case-insensitive, maybe something in the mypy cache is? |
I'm experiencing this issue as well in my Django projects.
Configuration:
I'm getting pretty much what @choogeboom is getting:
Even with the strange duplicate
Funny thing is, my coworkers that are using Windows as host do not have the same error. It also doesn't occur on our CI machines. I also have an inkling that it has something to do with importing these classes through |
What I have is three files:
And a file from .a import ModelA
from .b import ModelB
from .c import ModelC
__all__ = ["ModelA", "ModelB", "ModelC"] All of my code imports from |
We have a similar structure in our codebase. Everything outside |
Can you give the full module hierarchy + all the names defined in the relevant modules? Also I'd like to see the relevant Does the removal of Is there both a class Can you double check that your file system is not case insensitive? Even on Linux it's possible to have case insensitive file systems, I think. |
This is about as simple as a test as I can come up with: https://github.com/paulcwatts/mypytest It definitely is strange. I can't repro the issue with just the code -- it has to be within the Docker container. What's more, the code itself has to be mounted as a volume. First build the image:
Then, if you run mypy with code in the image:
If you run mypy with the code mounted on a volume:
It seems like it might have something to do with what gets stored in the mypy cache:
As opposed to:
|
And to answer your question, @JukkaL , the host file system is case insensitive (APFS), but the container file system (ext4) is not. That might have something to do with it? |
It looks like this might have something to do with it? #10093 . "On Linux we skip all logic, since the file system is almost always case sensitive. " This is one case where that assumption doesn't apply. |
Just wanted to chime in that I ran into this exact issue, and I believe I have independently confirmed both of @paulcwatts 's conclusions. I was working on some python code on a mac with a case-insensitive filesystem using VS Code's container remote extension. The VS Code remote extension automatically bind-mounts the source code on the case-insensitive mac into the linux container. Issue on the related repo with the errors: ExaWorks/psij-python#47 I tested the same codebase with mypy v0.800 (before the linked PR #10093 was merge) and the issue disappeared. It seems that in order to handle these edge cases, there needs to be someway to turn off the "platform == Linux" short-circuit for the case-sensitivity checking, since a case-insensitive filesystem could still be mounted into a linux VM/container. If anyone has any ideas/pointers for how to accomplish that (I'm unfamiliar with mypy's codebase/configuration/practices), I'd be willing to take a stab at implementing it and submitting a PR. Would a command-line flag be acceptable? Any other ideas? |
Realizing that this test wasn't all that rigorous, I went ahead and grabbed the latest mypy from git and the problem is still around:
Removed the linux shortcircuit (see git diff below) and the problem went away:
So I think that is pretty conclusive.
To be more specific, would a environment-specific configuration option like Maybe the best option is to just remove the short-circuit all together so that this issue is guaranteed to not occur, regardless of system configuration? |
And we have the same issue in docker on a mac, and reproducible with https://github.com/zidarsk8/mypy-mac-docker |
Originally added in python#10093 Fixes python#11690, fixes python#10661, fixes python#10822
Originally added in python#10093 Fixes python#11690, fixes python#10661, fixes python#10822 Co-authored-by: hauntsaninja <>
Bug Report
I want to apologize in advance for the somewhat vague nature of this bug report. I've tried for hours in order to create a reproducible example, and have failed. Unfortunately, the bug occurs in some proprietary code, so I can't release it to you all to look at.
I went to upgrade my project to use mypy 0.902 and after fixing all the expected errors related to third party stub libraries, I am left with the following two errors:
These errors are really strange, because there isn't any class called
buyfair.model.Warehouse.Warehouse
orbuyfair.model.Product.Product
. I shrugged my shoulders and added# type: ignore
to each of these, and tried to runmypy
again only to receive the following errors:I've set
warn_unused_ignores=False
and will move on, but figured this is at least worth reporting.To Reproduce
Like I said above, I tried to reproduce this error in a smaller more self-contained example for a few hours, but wasn't successful. I'll try to give more details around the context in the error messages above:
buyfair/model/warehouse.py
buyfair/model/product.py
In both these cases, mypy is replacing the module name with the class name.
buyfair.model.product.Product
becomesbuyfair.model.Product.Product
andbuyfair.model.warehouse.Warehouse
becomesbuyfair.model.Warehouse.Warehouse
Expected Behavior
In both these cases, the types work out just fine, and mypy should recognize the types just fine.
Actual Behavior
mypy fails to recognize the types correctly and creates a new made up type.
(Write what happened.)
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: