<p dir="ltr"><br>
On May 30, 2016 6:20 PM, "Guido van Rossum" <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
><br>
> In mypy we have a need for type variables, which are created like this:<br>
><br>
>   from typing import TypeVar<br>
><br>
>   T = TypeVar('T')<br>
><br>
> I just saw a lightning talk about sympy where they define symbols to<br>
> be used in mathematical equations, like this:<br>
><br>
>   from sympy import Symbol<br>
><br>
>   x = Symbol('x')<br>
><br>
> I'm sure this is not a new idea, but so far I've always thought that<br>
> this is pretty esoteric and the approach here is good enough. But<br>
> maybe we can actually do better....</p>
<p dir="ltr">One of the negatives of the above usages is that the two names don't have to match. I can do:</p>
<p dir="ltr">Q = TypeVar('U')</p>
<p dir="ltr">for example. Dedicated syntax could fix that, e.g.,</p>
<p dir="ltr">from typing import TypeVar as T$</p>
<p dir="ltr">And instead of writing x I write T$x. That compiles to a call to TypeVar('x'). A function imported this way would be required to always return the same value. That is T$xyz is T$xyz and the compiler would be free to optimize calls away or not. If I want a runtime eval that won't be optimized away I can write T$('x' + 'yz') which is T$xyz.</p>
<p dir="ltr">Of course $ could be :: or ! or something else.x</p>
<p dir="ltr">Nothing prevents me from writing </p>
<p dir="ltr">x = T$x</p>
<p dir="ltr">but I can be assured that this is the same as T$x elsewhere (barring different code importing different functions under the same name).</p>
<p dir="ltr">--- Bruce</p>