[conformance] Add examples that require bidi inference of list literals after specialization inference#2300
Open
dcreager wants to merge 1 commit into
Open
[conformance] Add examples that require bidi inference of list literals after specialization inference#2300dcreager wants to merge 1 commit into
dcreager wants to merge 1 commit into
Conversation
…ls after specialization inference
Member
|
I agree with changing this, but the proposal to require type checkers to infer the union also doesn't feel right. This test isn't about testing precise inference behaviors, it's about testing class constructors. Type inference behavior in cases like this test isn't specified precisely, so we shouldn't force a specific behavior in the conformance suite. The same behavior is observable in a simpler function: def f[T](x: list[T], y: list[T]):
pass
f([1], ["x"])is currently rejected by all type checkers in multiplay. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The conformance suite currently contains the following example:
typing/conformance/tests/constructors_callable.py
Lines 178 to 186 in 94514b1
The important point is that
r8is a generic callable. (There isn't a syntax that lets us easily spell a generic callable type usingCallable, so we had to jump through the small hoop ofaccept_callableto obtain it.) It has the following signature:Previously, the last line of this example would require that if you pass in list literals of different types, it should be a type inference error. However, the union of the two lists' respective element types is a valid solution — in this case,
T = int | str.I've updated these examples so that they are expected to succeed.
Open question: I also had considered marking them as
E?, since it does require a more complex specialization inference process that we might not want to mandate.I've also added additional tests for examples where there is genuinely no valid specialization: when one of the arguments is not a list at all, and where the typevar is bounded and the argument is a list that cannot possibly satisfy the upper bound.