[Python-Dev] Why does Signature.from_function() have to check the type of its argument?
pje at telecommunity.com
Sun Feb 10 22:46:06 CET 2013
On Fri, Feb 8, 2013 at 5:44 PM, Stefan Behnel <stefan_ml at 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...)
More information about the Python-Dev