-
-
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
AssertionError: Cannot find X for Y.X (incremental with warm cache) #2535
Comments
OK, simple repro: run
from typing import NamedTuple
class C:
def f(self) -> None:
A = NamedTuple('A', [('x', int), ('y', int)])
import ntcrash |
The problem is in the code that @kirbyfan64 fixed -- it's still broken in this case due to the peculiarities of how namedtuple classes are bootstrapped in the mypy code. |
Is this the 5th item in #2090 - "handle locally-defined namedtuple"? |
Yes, that's right. I'm not sure how to resolve it. Maybe the "qualified name" should be similar to what we use at runtime? E.g. with this code class C:
def f(self):
class D: pass
return D()
d = C().f()
print(d.__class__.__qualname__) the output is Thinking aloud, another possibility would be to give the inner class a synthetic qualified name starting with a digit, e.g. |
(The key requirement here being simply that whatever the qualified name is can be found by the lookup method in fixup.py. We may have to modify both the qualified name and the lookup function to deal with the special case.) |
I'm going crazy. I can only make my repro "work" (i.e. cause the AssertionError) if I make main.py import a non-existent symbol from ntcrash, e.g. |
It's unrelated to the content. You should |
That doesn't work for me. I delete the cache before starting. I really do have import something non-existing from ntcrash into main. |
Here's a test with the repro: ead98b3 |
Note there are other variants, e.g. class C:
def a(self) -> None:
class D:
def f(self) -> None:
A = NamedTuple('A', [('x', int), ('y', int)]) |
For me it works only if I touch main.py after ntcrash.py
|
The problem is still there if the code in from typing import NamedTuple
class C:
def f(self) -> None:
class D:
class E:
def g(self) -> None:
A = NamedTuple('A', [('x', int), ('y', int)])
self.a = A(1, 1)
self.c = D.E().a This could be easily fixed by always storing "anonymous" named tuples in |
@ilevkivskyi Can you create a new issue for the remaining problem, since otherwise it's easy to miss? We can tag it as low priority, but I'd like to keep track of crash bugs. |
@ilevkivskyi Thanks! |
This is similar to #2451 but the cause is different. I haven't boiled it down yet but the clue seems to be there's a NamedTuple definition inside a [EDITs from here:] for-loop inside a method. And another report where there's a namedtuple inside a method.
The text was updated successfully, but these errors were encountered: