Skip to content

Metaclass lost with slots=True  #154

@YevIgn

Description

@YevIgn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions