I don’t think proposals that use TypeVar(“T”) offer enough improvement over the status quo to be worth the tooling changes.
Here's another notation idea:
```
def two_tvars[T := TypeVar("T"), U := TypeVar("U")](x: T, y: U) -> T | U:
return x if x else y
```
Here (1) the walrus operator is used to bring T and U into scope, and
(2) a def expression allows an arbitrary indexed expression directly
after the function name, whose value is discarded at runtime.
Pros:
* Minimum of new syntax introduced.
* And this syntax *might* be useful for non-typing use cases
(which seems to be a general consideration for approving syntax
changes).
Cons:
* It's verbose.
* Still has noise related to having T and U mentioned twice it its
TypeVar definition.
* Leaves TypeVars (like T and U) in scope after the function definition.
--
David Foster | Seattle, WA, USA
Contributor to TypedDict, mypy, and Python's typing system
_______________________________________________
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: guido@python.org
--
--Guido (mobile)