-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
"Cannot determine type" on innocent but import-cycled code #2015
Comments
We get the error if Here are some ideas for improving this:
|
i hit what I believe to be this bug twice recently. annotating the variable didn't help. i played around with the order to try and resolve it, and it took some guessing and a few tries but I figured it out. however as we type more and more files, i'm worried we might become unable to work around this (other than removing cycles like these, which we're trying to add mypy to aid with =D). |
Just got a much smaller repro, 3 files! interface.py:
reporting.py:
i18n.py
This only happens when the files are checked in the following orders: But works when checked in this order: It fails both with --py2 and without it. Also some of the issues go away if I change my imports to EDITED: Removed issues caused by not typing do_stuff. |
That's because we try to break the import cycles by prioritizing dependencies, and We're actually hoping that a fair fraction if cycle-related problems can be made to go away by assigning more subtle priorities, e.g. an import used for a base class may get an even higher priority. |
David suggested a fix for many occurrences: instead of writing
(and then using
(and then using |
Ack. Just noticed that Any shows up because def do_stuff(self): doesn't have a type annotation. So never mind that part. I edited the post to remove that. |
This really is the same issue as #481, and I'm going to close this one as a duplicate (even though I like the example from the first comment). |
Sorry, reopening because this example must be fixed by improving the import order; it cannot be fixed by deferring the processing of functions. |
This will be fixed by #2167. (Note that the two examples are almost but not quite the same. The way Thing is derived from socket.socket in part2.py differs, and the resulting error message also differs. But both are fixed by the indicated PR.) |
Fixed by #2167. |
The following code is perfectly well-typed, but -- depending on the order files are passed to
mypy
-- gives a cryptic error message:On running
mypy part[1234].py
, we get the resultThe import cycle seems to be essential. The result is also sensitive to order -- for example,
mypy part{1,3,2,4}.py
gives no error.The repro can probably be reduced further; for example, I suspect there's a way to see it with three files, perhaps just two.
The code above obviously looks somewhat artificial -- it's stripped down from an example in a large internal codebase at Dropbox. We've seen several different people independently run into errors that look much like this in different parts of the same codebase, which has a number of import cycles, and I suspect the same thing is likely to happen in other large import-cycled codebases elsewhere. It'd be valuable to understand just what's going on here.
At a minimum, we should give a clear error message -- this one is pretty unhelpful for the user. Better yet we should fix the issue :), but import cycles have been tricky for us before so that might be difficult. If we can't immediately fix it, though, it'd be helpful even just to know what the obstacle is in this case.
The text was updated successfully, but these errors were encountered: