Add TypeForm (PEP 747) to the spec and conformance suite#2183
Add TypeForm (PEP 747) to the spec and conformance suite#2183JelleZijlstra wants to merge 7 commits intopython:mainfrom
Conversation
davidhalter
left a comment
There was a problem hiding this comment.
Thanks for the quick addition, I think some cases where clarifications would be great (and that are also not really mentioned in the PEP):
def f(x: TypeForm[int | str]): ...
# Are these all fine or not? These are not normal statements and it's quite unusual to
# infer arguments in this way whereas things like `x: TypeAlias = int` are more typical.
# I personally don't care if this is inferred or not, just that it is part of the conformance tests.
f(int)
f(int | str)
f("int")
# There are obviously more complicated cases for type inference like this one:
def g(x: list[TypeForm[int]]): ...
g([int])
g(["int"])
g([TypeForm("int")]) # Obviously fine
This would obviously affect all type inference for all type checkers in quite a big way. Again, I'm just not sure what the PEP wants here, but you can probably clarify. Here I would probably also prefer that at least some of the above cases are added to the conformance tests, because otherwise we would have different behavior for inference in a feature that doesn't really need that. Type inference is already a big mess across type checkers.
| v1_type_form: TypeForm[str | None] = str | None # OK | ||
|
|
||
| v2_actual: types.GenericAlias = list[int] # OK | ||
| v2_type_form: TypeForm = list[int] # OK |
There was a problem hiding this comment.
I would like this case to be clarified with an additional
assert_type(v2_type_form, TypeForm[Any])
since the PEP mentions that this case is not inferred, but Any (which seems reasonable). But I would like this to be consistent across type checkers.
|
Another thing that I just remember is the case of Here I would also like some guidance. Are type checkers expected to store more information than |
No description provided.