4 ms·
“The new syntax allows declaring TypeVarTuple and ParamSpec parameters, as well as TypeVar parameters with bounds or constraints:” ``` ... type Int
by thatxliner 3y ago
“The new syntax allows declaring TypeVarTuple and ParamSpec parameters, as well as TypeVar parameters with bounds or constraints:”
```
...
type IntOrStrSequence[T: (int, str)] = Sequence[T] # TypeVar with constraints
```
Why can’t the syntax be
```
type IntOrStrSequence[T: int | str] = Sequence[T]
```
- bayangan 3y agoI think because that conflicts with the `bound` syntax which expects a single type.
- thatxliner 3y agoUnless I’m mistaken, bound constrains the type to a specific protocol while this constrains the type to specific types.