El vie, 1 jul 2022 a las 10:48, Eric Traut (<eric@traut.com>) escribió:
Actually I like T(int) a lot, and it avoids giving new meanings to ':'
I'm somewhat negative on `T(int)`. It looks to me like a function call, which isn't the right mental model in this case. It's "giving new meaning to a function call syntax" which is well established in Python.
I guess one could argue that it's intended to look like a constructor call, but "constructing" type parameters is a weird mental model. No other programming language that supports generics forces users to think of "constructing" type parameters.
IMO, the `:` provides the appropriate mental model. A type parameter is similar to a function parameter, just a meta-level above. Like a function parameter, a type parameter can have a type that constrains its usage when arguments are provided. Function arguments are provided by function calls at runtime, whereas type arguments are provided through implicit or explicit specialization at type checking time. So I don't think this gives new meaning to the colon token. I think it's using the colon consistently with how it's already used elsewhere in the language.
It's a bit different though in that the type parameter's bound is not the type of the variable. If we have something like `def f[T, U: int](x: T, y: U)`, it kind of looks like `U` is a variable of type int and `T` is unannotated. What about using <: like in Scala? def f[T, U <: int](x: T, y: U): ...
-Eric _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: jelle.zijlstra@gmail.com