On Mon, Mar 7, 2022 at 3:11 AM Sebastian Rittau <srittau@rittau.biz> wrote:
Ideally, generics would be initialized at the point where they are used,
like in all other languages I'm familiar with. But I don't think we can
do this is in a readable manner without new syntax, and that is unlikely
to happen soon, considering the SC's stance on typing features.
I wouldn't be quite so pessimistic. The SC rejected PEP 677 at least in part because, being a type annotation, it has to be an expression, but it's a form of expression that's not useful in other contexts.
If we're considering syntax to replace TypeVar(), like
def foo<T>(arg1: T, arg2: T) -> list[T]:...
class C<T, S>:def __init__(self, arg1: T, arg2: S):self.attr1 = arg1self.attr2 = attr2
...
that would not be general expression syntax. (It would be good to poll on python-dev what people would think of such a proposal though.)
Not python-dev and not really relevant for this discussion, but I would really like to see "standard" generic syntax, as in your example, in Python.
- Sebastian