Skip to content

Commit

Permalink
define __slots__ in all base classes
Browse files Browse the repository at this point in the history
...otherwise there it does not do anything. add a test for this.
  • Loading branch information
wbolster committed Jul 2, 2017
1 parent 1271c81 commit a3830ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sanest/sanest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Collection(
collections.abc.Sized,
collections.abc.Iterable,
collections.abc.Container):
pass
__slots__ = ()

ATOMIC_TYPES = (bool, float, int, str)
CONTAINER_TYPES = (builtins.dict, builtins.list)
Expand Down Expand Up @@ -404,6 +404,8 @@ class SaneCollection(Collection):
"""
Base class for ``sanest.dict`` and ``sanest.list``.
"""
__slots__ = ()

@abc.abstractmethod
def wrap(cls, data, *, check=True):
raise NotImplementedError # pragma: no cover
Expand Down
9 changes: 9 additions & 0 deletions test_sanest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,15 @@ def test_missing_arg_repr():
assert str(_sanest.MISSING) == '<missing>'


def test_slots():
d = sanest.dict()
with pytest.raises(AttributeError):
d.foo = 123
l = sanest.list()
with pytest.raises(AttributeError):
l.foo = 123


def dedent(s):
s = s.lstrip('\n')
s = textwrap.dedent(s).rstrip()
Expand Down

0 comments on commit a3830ad

Please sign in to comment.