-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[0.530] AssertionError: Internal error: Unresolved forward reference to UnboundType #4097
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
Comments
This is something related to a forward reference. Far example: x: 'A'
A = List[int] There is a chance (but not 100%) that you have a Can you actually share the code? Alternatively I can prepare a "diagnostic" branch and then you could show me the output. |
Unfortunately I can't share the code since it's closed source. I'll try to figure out which sub module is causing it and try to find a minimal reproduction. The codebase is python2, if that helps. |
Running with
I can confirm that running it on that single file fails, I'll try to minimize |
It's something a little more complicated than just that. The file contains a line similar to |
This is a very good hint. I remember having problems with NewTypes I thought have cleaned-up them all, probably not. |
Could you please grep for the places where |
It looks like it's used in multiple files.
|
In particular, does it appear in an overload function signature? I have found a repro, but it is not related to NewTypes, it can happen with any broken forward reference in an overload. |
The codebase doesn't have any uses of |
OK, this means that we have at least two crashes :-) |
Could you please try the original crash with mypy installed from current master? How does the crash look like? (There are chances it will crash differently.) |
|
I tried to play with this for some time, but still can't get a repro. It is quite mysterious, since the code provoking the crash looks very simple, from the traceback I see that there is a method (most likely in a module level class) that has one of the argument types of the form @Daenyth maybe you could find one of such methods, and isolate the related code, i.e. keep the import structure between files, but only leave the necessary definitions in the corresponding files, i.e. something like this: # file a.py
from c import C
Foo = NewType('NotFoo', int)
# file b.py
from a import Foo
Bar = Tuple[Foo, int]
# file c.py
from b import Bar
class C:
def meth(self, x):
# type: (List[Bar]) -> None
pass And then see if this causes the crash? This will be very helpful. |
OK, I was able to make a reproduction into a single file. The stack trace I get is not exactly the same as running on the real code, but it's a crash, and a similar message. # This is python2
from __future__ import absolute_import, division, print_function, unicode_literals
from typing import Any, Dict, List, NewType
Foo = NewType('NotFoo', int)
Foos = NewType('Foos', List[Foo])
def frob_the_widget(foos):
# type: (Dict[Any, Foos]) -> None
f = foos.get(1)
reveal_type(f)
list(f) Removing the
|
Thank you! I will make a fix tomorrow and you can then test if it fixes the original crash (with all files). |
At least I can reproduce the original traceback with slightly modified repro. |
This adds processing of forward references in two nodes that were previously missing: `OverloadedFuncDef` and `NewTypeExpr.info`. (Note that some tests use `# type: ignore`, the original crash was discovered during serialization with errors ignored.) Fixes #4097.
This adds processing of forward references in two nodes that were previously missing: `OverloadedFuncDef` and `NewTypeExpr.info`. (Note that some tests use `# type: ignore`, the original crash was discovered during serialization with errors ignored.) Fixes #4097.
I get this running on my codebase after updating to 0.530. It passes without error in 0.521. I'm not sure what's triggering it - if you can help me figure that out I can try to minimize the failure.
The text was updated successfully, but these errors were encountered: