Prevent crash on generic NamedTuple with unresolved typevar bound#18585
Prevent crash on generic NamedTuple with unresolved typevar bound#18585ilevkivskyi merged 6 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks for taking a look, this makes sense. Let's merge this and try and get it into the release, since it's been reported multiple times.
I'm not sure about TypeQuery / BoolTypeQuery, probably makes sense to try? Would also be good to try and get a regression test working.
|
Nice catch! Yes, I think fixing this in For more context, |
This comment has been minimized.
This comment has been minimized.
|
Both primer hits appear to reveal a different problem, reproducible as follows: The inferred type is: nothing suspicious, but... So when inferring list expr type as a constructor call, we synthetize a fully defined tuple with a partially unknown fallback (union of all initial values). I think it's fine to keep for now and investigate separately? And I'm still unable to write a testcase for the original problem, any suggestions are welcome! |
|
Alternatively, we can exclude fallback in |
This looks like a good short-term solution. Long term we may actually want to completely erase the fallback argument in Could you please skip fallback for now, and add a TODO there? (And maybe make a follow up PR if you have time) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
OK, so here is the repro for the crash (should be added to any of the incremental test files). The caveat is that repro requires #18592, as I didn't find any existing test fixture with a |
This makes it more similar to the real typeshed. It is needed to reproduce tricky failures in tests, e.g. #18585. If this causes slower tests, some tests may be switched to `tuple-simple.pyi`.
|
Since this is a prominent crashing bug, I'll try to cherry pick it for the 1.15 release if it lands in the next couple of days. If it's not ready by that point, I can prioritize cutting a quick 1.15.1 release to pick it up instead. |
|
Thank you @ilevkivskyi! I missed the Self-type relation. I verified that this testcase fails on current master and passes here. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This makes it more similar to the real typeshed. It is needed to reproduce tricky failures in tests, e.g. #18585. If this causes slower tests, some tests may be switched to `tuple-simple.pyi`.
This makes it more similar to the real typeshed. It is needed to reproduce tricky failures in tests, e.g. #18585. If this causes slower tests, some tests may be switched to `tuple-simple.pyi`.
This makes it more similar to the real typeshed. It is needed to reproduce tricky failures in tests, e.g. python#18585. If this causes slower tests, some tests may be switched to `tuple-simple.pyi`.
…thon#18585) Fixes python#18582. Fixes python#17396. Supersedes python#18351. --------- Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
Removes todo added in python#18585 - such normalization is not technically correct when a tuple is used as a base class. --------- Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
Fixes #18582. Fixes #17396. Supersedes #18351.
cc @hauntsaninja - see my comments on your original PR, maybe this change should be lifted to BoolTypeQuery and TypeQuery instead? (opening a separate PR to see CI results)