Python is DOOMED! Again!

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 22 23:08:14 CET 2015


On Thu, Jan 22, 2015 at 2:56 PM, Emile van Sebille <emile at fenx.com> wrote:
> I've been lightly scanning and following the PEP 484 discussion, and one
> point I don't think I've seen mentioned is how you might hint a function
> that accepts different types, eg:
>
> def adder(a,b): return a+b
>
> This is one of the pythonic idioms that help with polymorphic functions.  Is
> there a proposal for providing hinting for these?

You can use TypeVar for that.

T = TypeVar('T')

def adder(a: T, b: T) -> T:
    return a + b

I'm not thrilled about having to actually declare T in this sort of
situation, but I don't have a better proposal.



More information about the Python-list mailing list