Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot do instance check on autoray.numpy and ABC #20

Closed
williamwen42 opened this issue May 10, 2024 · 1 comment · Fixed by #21
Closed

Cannot do instance check on autoray.numpy and ABC #20

williamwen42 opened this issue May 10, 2024 · 1 comment · Fixed by #21

Comments

@williamwen42
Copy link

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?

@williamwen42 williamwen42 changed the title Cannot do instance check on autoray.numpy Cannot do instance check on autoray.numpy and ABC May 10, 2024
@jcmgray
Copy link
Owner

jcmgray commented May 10, 2024

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

jcmgray added a commit that referenced this issue May 10, 2024
fix NumpyMimic special attribute access (#20)
williamwen42 added a commit to pytorch/pytorch that referenced this issue May 14, 2024
Fixes #93624 but also requires jcmgray/autoray#20 to be fixed.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang

[ghstack-poisoned]
williamwen42 added a commit to pytorch/pytorch that referenced this issue May 14, 2024
Fixes #93624 but also requires jcmgray/autoray#20 to be fixed.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang

[ghstack-poisoned]
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue May 15, 2024
Fixes #93624 but also requires jcmgray/autoray#20 to be fixed.

Pull Request resolved: #125945
Approved by: https://github.com/jansel
ghstack dependencies: #125882, #125943
ZelboK pushed a commit to ZelboK/pytorch that referenced this issue May 19, 2024
Fixes pytorch#93624 but also requires jcmgray/autoray#20 to be fixed.

Pull Request resolved: pytorch#125945
Approved by: https://github.com/jansel
ghstack dependencies: pytorch#125882, pytorch#125943
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants