[IPython-dev] Next-gen result printing using generics
Walter Dörwald
walter@livinglogic...
Sat May 26 07:34:59 CDT 2007
Ville M. Vainio wrote:
> On 5/26/07, Walter Dörwald <walter@livinglogic.de> wrote:
>
>> That was going through my head too. However the current display hook
>> fires for subclasses of Table too (that's why you can type ils instead
>> of ils()). For this to work, we'd need a when_subclass() decorator in
>> simplegeneric.
>
> Doesn't when_type do this?
No, it checks the class of the argument not the argument itself:
In [1]: from simplegeneric import *
In [2]: @generic
...: def foo(x):
...: print x
...:
...:
In [3]: @foo.when_type(int)
...: def foo_int(x):
...: print "int", x
...:
...:
In [4]: foo(42)
int 42
In [5]: foo(int)
<type 'int'>
> I see the MRO mentioned in the sources anyway...
Yes, but it iterates the MRO of the class of the argument to find an
implementation, so passing the class will iterate the MRO of type (or
types.ClassType for old-style classes).
Servus,
Walter
More information about the IPython-dev
mailing list