Python is DOOMED! Again!

Paul Rubin no.email at nospam.invalid
Thu Jan 22 18:24:01 EST 2015


Ian Kelly <ian.g.kelly at gmail.com> writes:
> T = TypeVar('T')
> def adder(a: T, b: T) -> T:  ...
> I'm not thrilled about having to actually declare T in this sort of
> situation, but I don't have a better proposal.

Oh man, that's ugly.  Maybe a decorator would be a bit less awful:

    @-typevar T
    def adder(a: T, b: T) -> T: ...

I'm using @- for a hypothetical decorator that receives the AST for the
stuff on the rest of the line, instead of being evaluated as a function.

The above looks sort of like C++, which would say

  template <typename T>
  T addr (T a, T b) { ... }




More information about the Python-list mailing list