Cannot do instance check on autoray.numpy and ABC
williamwen42 opened this issue · comments
William Wen commented
Found when trying to fix pytorch/pytorch#93624.
Repro:
from abc import ABC
from autoray import numpy as np
class Base(ABC):
pass
isinstance(np, Base)
Error:
Traceback (most recent call last):
File "/data/users/williamwen/pytorch2/playground3.py", line 7, in <module>
isinstance(np, Base)
File "/data/users/williamwen/py310-env/lib/python3.10/abc.py", line 119, in __instancecheck__
return _abc_instancecheck(cls, instance)
File "/data/users/williamwen/py310-env/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
I got around this by adding
if fn == "__class__":
return NumpyMimic
in the NumpyMimic
class __getattribute__
. Perhaps additional cases need to be added as well?
Johnnie Gray commented
Thanks for the issue, should be fixed by #21, will merge and mint a release shortly.