-
-
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
Fix crash from NamedTuple placeholder #18351
base: master
Are you sure you want to change the base?
Conversation
Fixes python#17396 I'm having trouble writing a regression test, but the following reproduces the issue nicely: ``` rm -rf repro mkdir repro mkdir repro/np echo 'from .arraysetops import UniqueAllResult' > repro/np/__init__.pyi echo ' from typing import Generic, NamedTuple, TypeVar from np import does_not_exist _SCT = TypeVar("_SCT", bound=does_not_exist) class UniqueAllResult(NamedTuple, Generic[_SCT]): values: int ' > repro/np/arraysetops.pyi touch repro/np/py.typed PYTHONPATH=repro mypy -c 'import np' ```
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit hacky, but I guess it may be a necessary evil. Two things:
- Is there the same issue with generic TypedDicts? If yes, please fix that as well (and maybe try adding a test)
- Can you verify that a pattern like this still works? (And maybe add a corresponding test if we don't have one):
T = TypeVar("T", bound="NT")
class NT(NamedTuple, Generic[T]):
parent: T
item: int
Thanks for the review!
|
See #18351 (review) Co-authored-by: ilevkivskyi
Hm, I think this requires further investigation. NamedTuples and TypedDicts are almost identical w.r.t. deferrals etc. This may indicate that there is a simpler/better fix, or there is something deeper going on. I would recommend adding some debugging prints in a repro that mirrors the NmaedTuple one, and see what types appear there (it may be that there are still some unresolved placeholders, but they don't cause a crash in case of TypedDicts for some reason). |
Fixes #17396
I'm having trouble writing a regression test, but the following reproduces the issue nicely: