Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot use issubclass on decorated class derived from abc.ABC #130

@SeppMe

Description

@SeppMe

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 printing True as I would expect:

import wrapt
import abc

class Base(abc.ABC):
    pass

@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
    return wrapped(*args, **kwargs)

@pass_through
class Klass(Base):
    pass

print(issubclass(Klass, Base))

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

import wrapt
import abc

@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
    return wrapped(*args, **kwargs)

@pass_through
class Klass(abc.ABC):
    pass

print(issubclass(Klass, abc.ABC))

but I chose the first example because it demonstrates better what I want to achieve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions