-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
TypeAliasType with should also raise an error if non-default type parameter follows default type parameter #124787
Comments
Related to: python/cpython#124787
I would like to work on this, if no one else has already started. We need to check both Python API and our internal |
|
There's one more problem that I've noticed. This is allowed: Was allowed :) |
👀 I have the suspicion that everything(?) can be passed as long as it is packed in a tuple. One could argue that this is a job for type-checkers to detect. But, where does one draw the line 😅? I have no opinion here btw. I found another case that is invalid, a repeated type parameter, see https://peps.python.org/pep-0695/#specification. type A[T, T] = ... # SyntaxError
type B[T, *T] = ... # SyntaxError
type C[T, **T] = ... # SyntaxError |
A question PEP 696 states
class G[*Ts, T=int]: ...
TypeError: Type parameter with a default follows TypeVarTuple but type Foo[*Ts, T=int] = tuple[*Ts] | list[T] is okay. Is this an oversight, or an exception? |
That's a runtime error, not a compile-time error. I think it's fine for the type statement (as well as generic functions) to be a bit more permissive at runtime here. |
Co-authored-by: Jelle Zijlstra <[email protected]>
Should this stay open or can we close it? |
Bug report
Bug description:
The following statement is invalid:
However, writing it as a
TypeAliasType
is possible. The following should likely raise an error as well to mimic this behavior:CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
TypeAliasType
and incorrecttype_params
#124795The text was updated successfully, but these errors were encountered: