Skip to content

Commit

Permalink
Preserve metaclass when slots=True (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
YevIgn authored and hynek committed Mar 7, 2017
1 parent 2c8bd46 commit c70a910
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest
zope.interface
pympler
hypothesis
six
2 changes: 1 addition & 1 deletion src/attr/_make.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)

0 comments on commit c70a910

Please sign in to comment.