Thanks for looking at this! This comes up in typeshed every now and then and is something that could be quite nice for evolving generically typed APIs.

I have a preference for having the defaults live close to the class. TypeVar scoping and binding is kind of confusing as is. Could you spell out what the backward compatibility concerns with `class Box(Generic[T], T=int)` are?
It sucks that we don't have PEP 637 for this. Maybe we consider doing something more dramatic like `class Box(Generic(S, T, U=int))`?

It might be worth spelling out the rules for generic subclasses of generic classes that both have defaulted TypeVars are.

It'd also be good to write up some more real-world-code places where this would be useful. To what extent would we still want this if we had a commonly used `GenIter = Generator[T, None, None]` generic type alias in typing.py?


On Fri, 4 Mar 2022 at 14:19, James H-B <gobot1234yt@gmail.com> wrote:
I've been toying with the idea of writting a PEP for this long requested feature (https://github.com/python/typing/issues/307).

I've got a preliminary draft of it with the motivation and a specification for the feature. In short features like
```py
T = TypeVar("T", default=int)  # This means that if no type is specified T = int

@dataclass
class Box(Generic[T]):
    value: T | None = None

reveal_type(Box())                      # type is Box[int]
reveal_type(Box(value="Hello World!"))  # type is Box[str]
```
would be supported as would
```py
YieldT = TypeVar("YieldT")
SendT = TypeVar("SendT", default=None)
ReturnT = TypeVar("ReturnT", default=None)

class Generator(Generic[YieldT, SendT, ReturnT]): ...

Generator[int] == Generator[int, None] == Generator[int, None, None]
```

Feedback and any questions on this would be very appreciated. https://gist.github.com/Gobot1234/8c9bfe8eb88f5ad42bf69b6f118033a7

Thanks,
James H-B.
_______________________________________________
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: hauntsaninja@gmail.com