Feb. 10, 2013
9:46 p.m.
On Fri, Feb 8, 2013 at 5:44 PM, Stefan Behnel <stefan_ml@behnel.de> wrote:
Argh - sorry, got it all wrong. "__instancecheck__()" works exactly the other way round. In the type check above, it's the FunctionType type that gets asked for an instance check, which doesn't help at all in this case because it simply doesn't know about the desired subtype relation. It would work if type(func).__instancecheck__() was used, but that doesn't happen.
So, no help from that side, sadly.
How about you return FunctionType as your __class__ attribute? ;-) Your type() will still be different, but isinstance() also considers the __class__ if it's different from the type(). (At least it does in 2.x, I've not tried it in any 3.x versions yet...)