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

Metaclass lost with slots=True #154

Closed
YevIgn opened this issue Feb 27, 2017 · 1 comment
Closed

Metaclass lost with slots=True #154

YevIgn opened this issue Feb 27, 2017 · 1 comment

Comments

@YevIgn
Copy link
Contributor

YevIgn commented Feb 27, 2017

Hello.

Using a metaclass with slots=True, e.g.

@attr.s(slots=True)
class A(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def f(self):
        pass

Will lead to A being instantiable and type(A) being <class 'type'> (unlike the case with slots=False), as for slots to work the new class is generated in _make.py with:

cls = type(cls.__name__, cls.__bases__, cls_dict) [1]

This doesn't happen if this line is changed to:

cls = type(cls)(cls.__name__, cls.__bases__, cls_dict) [2]

With this change type(A) is <class 'abc.ABCMeta'> and A is no longer instantiable.
Can the class generation for slots be changed to something like [2] to avoid losing metaclasses or it is intentionally written as it is now and I am missing something?

@Tinche
Copy link
Member

Tinche commented Feb 27, 2017

It's not intentional, it just hasn't come up until now. :)

Could you try applying the change, and if the tests pass contribute a PR? It'd be nice to add a test for this as well.

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