-
-
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
mypy gives valid-type errors with some import methods, seemingly inconsistently #10822
Comments
This sounds similar to #10661. |
Yes, definitely looks like it could be the same issue (I like that we both have similar apologies for not being able to simplify it too). The problems I was seeing were inside a Vagrant VM (Virtualbox) running on a Windows host, with the code in a synced folder from the host, so it seems very similar to what @paulcwatts showed there with Docker. My repo includes the Vagrantfile, so you should be able to get an equivalent setup easily with Vagrant and Virtualbox if you have a Windows/Mac machine available (for a case-insensitive host). Looking inside the
So it does seem like there might be conflicts in the cache due to case insensitivity, where the class and module are getting mixed up. |
It's probably not surprising, but since I tested it: disabling incremental mode or using an sqlite cache both don't help. |
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
Sorry in advance, this is going to be an non-ideal bug report. I've spent over an hour now trying to figure out how to create a simpler project that reproduces the issue, but I haven't been able to cause it to happen, so I'm going to have to use my real project as the example.
I recently updated mypy from 0.790 to 0.910, and it started giving a number of
[valid-type]
errors related to some of my classes, saying that I couldn't use them as type annotations. Here's one example:I had to make some different modifications to how I was importing the classes to get rid of these errors:
from .group import Group
. Using the full path likefrom tildes.models.group import Group
would result in an error.from tildes.models.user.user import User
, where every other "sibling" package can dofrom tildes.models.user import User
without mypy complaining (the class is imported in the__init__.py
to allow that).All of the changes I needed to make are in this commit if you want to look (there are also some fixes for legitimate typing issues in there too).
The second type of change above is the more interesting one, because I have some modules that are very close to identical, but require different import styles to make mypy happy.
If you compare these two files:
They're almost identical - the first one is a link between
User
+Group
, and the other is a link betweenUser
+Topic
. However, mypy needs me to do thefrom tildes.models.user.user import User
import ingroup_subscription.py
, but is fine withfrom tildes.models.user import User
intopic_vote.py
.To Reproduce
(Sorry again for having to use my actual project here)
git checkout 9720040cb9a7c75fd590322479e821a0e8f13497 -- tildes/tildes/models/group/group_subscription.py
(reverts the fix I made to that single file)tildes/
subdirectory, and runmypy .
Expected Behavior
mypy should support classes imported in any of the ways Python supports.
Actual Behavior
mypy seems to require specific import methods in certain cases.
Your Environment
mypy.ini
(and other config files): https://gitlab.com/tildes/tildes/-/blob/31afe0a8ba574988be4e879c9ab33792ceec9533/tildes/mypy.iniThe text was updated successfully, but these errors were encountered: