jcmgray / autoray

Abstract your array operations.

Home Page:https://autoray.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot do instance check on autoray.numpy and ABC

williamwen42 opened this issue · comments

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?

Thanks for the issue, should be fixed by #21, will merge and mint a release shortly.