I'm trying to make my class appear as a different object to circumvent lazy type checking in a package I'm using. More specifically, I'm trying to make my object appear as an instance of another object (tuple
in my case) when in reality it is not even a derivation of that.
In order to achieve this, I plan to overwrite the __isinstance__
method which, according to the docs, should do exactly what I desire. However, it appears that I didn't understand how do to do that exactly, because my attempts have been unsuccessful.
Here's an SSCCE that should make isinstance
return False
in all cases but doesn't.
class FalseInstance(type):
def __instancecheck__(self, instance):
return False
class Foo(metaclass=FalseInstance):
pass
g = Foo()
isinstance(g, Foo)
> True
What am I doing wrong?