-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use issubclass on decorated class derived from abc.ABC #130
Comments
Adding a decorator to a class presents a few issues which there are no solutions for. One is deriving from a decorated class. Another would be taking the type of the decorated class and using equality on it to see if something else matches the same rather than using Anyway, it falls into the same class of problem as: I try and dig into it further when I can. It sounds like the check is implemented in a C code extension if you can't track it through with a Python debugger. |
import abc
import wrapt
class Base(metaclass=abc.ABCMeta):
@classmethod
@abc.abstractmethod
def method(cls):
pass
class B(Base):
@classmethod
def method(cls):
print(f'In {cls.__name__}')
class C(B):
@classmethod
def method(cls):
print(f'In {cls.__name__}')
if __name__ == '__main__':
print(f'Ok {issubclass(C, B)}')
print(f'Not ok {issubclass(wrapt.ObjectProxy(C), B)}') The code above raises |
Fiddling with this a bit and using an example that contrasts with when abc.ABCMeta isn't used get:
with output of:
This is because the very first thing that
If it got past that strict type, it may well still work like the case where |
From looking at Python implementation found enough justification to believe should report a bug against Python standard library. They have a pure Python implementation which actually does the right thing, but it is only used for pypy. Bug report is: I have still made some changes to wrapt to handle some other cases with |
Not sure if this is an issue with wrapt or abc. The following code will raise a
TypeError: issubclass() arg 1 must be a class
instead of printingTrue
as I would expect:Apparently, abc.ABC replaces the subclasscheck with its own special subclasscheck, which in turn raises the exception. Unfortunately, that subclasscheck is some internal function that I cannot debug. The last arguments for this internal subclasscheck that the debugger can see are
<class '__main__.Base'>
and<class '__main__.Klass'>
, which looks fine to me.The example above can be simplified even further to
but I chose the first example because it demonstrates better what I want to achieve.
The text was updated successfully, but these errors were encountered: