On 4/12/21 7:24 PM, Guido van Rossum wrote:
To be honest, the most pressing issue with annotations is the clumsy way that type variables have to be introduced. The current convention, `T = TypeVar('T')`, is both verbose (why do I have to repeat the name?) and widely misunderstood (many help request for mypy and pyright follow from users making a mistaken association between two type variables that are unrelated but share the same TypeVar definition).


This repeat-the-name behavior has been in Python for a long time, e.g.

Point = namedtuple('Point', ['x', 'y'])

namedtuple() shipped with Python 2.6 in 2008.  So if that's the most pressing issue with annotations, annotations must be going quite well, because we've known about this for at least 13 years without attempting to solve it.

I've always assumed that this repetition was worth the minor inconvenience.  You only have to retype the name once, and the resulting code is clear and readable, with predictable behavior.  A small price to pay to preserve Python's famous readability.


For what it's worth--and forgive me for straying slightly into python-ideas territory--if we wanted to eliminate the need to repeat the name, I'd prefer a general-purpose solution rather than something tailored specifically for type hints.  In a recent private email conversation on a different topic, I proposed this syntax:

bind <id> <expression>

This statement would be equivalent to

id = expression('id')


Cheers,


/arry