I second the point on confusion around TypeVar declarations and scoping rules. I would very much like Python to have dedicated syntax for type parameters. However, given the recent discussion on python-dev and the position of the Steering Council on typing-only syntax, I'm not sure this is realistic... On Mon, Oct 25, 2021 at 5:12 AM Eric Traut <eric@traut.com> wrote:
Personally, I don't find `<=` to be very readable for bounds. Would the `is` operator be better? Or perhaps the `in` operator with a single-element tuple?
If there is going to be a push to add new syntax for TypeVar customizations, I'd rather see us first focus on addressing the a much bigger usability issue with type variables in Python today. Many Python users are confused by type variables because the allocation of a TypeVar is divorced from its use, and the scoping rules for a TypeVar are not obvious and difficult to understand even after reading PEP 484 and the mypy docs. The source of confusion doesn't exist in other language because type variables are defined in context where they are used, making their scopes obvious. Fixing this issue is way more important, IMO, than making it slightly easier to specify the variance of a TypeVar. I wouldn't want any of these proposed variance syntax changes to get in the way of fixing the larger issue.
I remember this broader issue being raised in the typing-sig previously, but I don't recall if anyone proposed a viable solution.
-Eric
-- Eric Traut Contributor to pyright & pylance Microsoft _______________________________________________ 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: sergei.a.lebedev@gmail.com