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

Preserve metaclass when slots=True #155

Merged
merged 5 commits into from Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
Expand Up @@ -3,3 +3,4 @@ pytest
zope.interface
pympler
hypothesis
six
2 changes: 1 addition & 1 deletion src/attr/_make.py
Expand Up @@ -362,7 +362,7 @@ def wrap(cls):
cls_dict.pop("__dict__", None)

qualname = getattr(cls, "__qualname__", None)
cls = type(cls.__name__, cls.__bases__, cls_dict)
cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
if qualname is not None:
cls.__qualname__ = qualname

Expand Down
21 changes: 21 additions & 0 deletions tests/test_dark_magic.py
Expand Up @@ -3,6 +3,7 @@
import pickle

import pytest
import six

from hypothesis import given
from hypothesis.strategies import booleans
Expand Down Expand Up @@ -82,6 +83,22 @@ class FrozenNoSlots(object):
x = attr.ib()


class Meta(type):
pass


@attr.s
@six.add_metaclass(Meta)
class WithMeta(object):
pass


@attr.s(slots=True)
@six.add_metaclass(Meta)
class WithMetaSlots(object):
pass


class TestDarkMagic(object):
"""
Integration tests.
Expand Down Expand Up @@ -231,3 +248,7 @@ def test_subclassing_frozen_gives_frozen(self):

assert i.x == "foo"
assert i.y == "bar"

@pytest.mark.parametrize("cls", [WithMeta, WithMetaSlots])
def test_metaclass_preserved(self, cls):
assert Meta == type(cls)