[RFC] Parametric Polymorphism

Catalin Marinas catalin.marinas at gmail.com
Mon Sep 26 05:52:48 EDT 2005


Tom Anderson <twic at urchin.earth.li> wrote:
> Is there any reason you have to stringify the type signature? Types
> are hashable, so a tuple of types is hashable, so you can just use
> that as a key. Replace "methods[f.func_name][str(types)] = f" with
> "methods[f.func_name][types] = f" and "type_str = str(tuple([type(arg)
> for arg in args]))" with "type_str = tuple(type(arg) for arg in
> args)". And then rename type_str to types thoughout.

You're right. I initially had a list in there and it wasn't hashable
(and I thought tuples aren't either). Anyway, the implementation is
just an example, it should use isinstance() instead. The link posted
by Kay shows a better implementation.

-- 
Catalin



More information about the Python-list mailing list