Skip to content
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

Can't inherit from a proxied class #80

Open
benrg opened this issue Jan 24, 2024 · 1 comment
Open

Can't inherit from a proxied class #80

benrg opened this issue Jan 24, 2024 · 1 comment

Comments

@benrg
Copy link

benrg commented Jan 24, 2024

In 1.10.0, this fails with a TypeError:

import lazy_object_proxy

@lazy_object_proxy.Proxy
def Base():
    class Base: pass
    return Base

class Derived(Base): pass

The problem is that class takes type(Base) to be Derived's metaclass, and calls it with three arguments, but Proxy.__init__ expects only one.

Adding three metaclass methods to Proxy appears to fix the problem:

class FixedProxy(lazy_object_proxy.Proxy):
    def __mro_entries__(self, bases):
        return (self.__wrapped__,)

    def __subclasscheck__(self, subclass):
        return issubclass(subclass, self.__wrapped__)

    def __instancecheck__(self, instance):
        return isinstance(instance, self.__wrapped__)
@Atry
Copy link

Atry commented May 1, 2024

I created a PR #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants