diff --git a/setup.cfg b/setup.cfg index 9419a157..9f536bba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,6 +14,7 @@ addopts = -ra testpaths = tests filterwarnings = once::Warning + ignore:::pympler[.*] [isort] diff --git a/setup.py b/setup.py index e382d1bd..e6ea4b55 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ EXTRAS_REQUIRE = { "coverage", "hypothesis", "pympler", - "pytest", + "pytest<3.9", "six", "zope.interface", ], diff --git a/src/attr/_compat.py b/src/attr/_compat.py index 5bb06593..1a1db573 100644 --- a/src/attr/_compat.py +++ b/src/attr/_compat.py @@ -20,6 +20,7 @@ else: if PY2: from UserDict import IterableUserDict + from collections import Mapping, Sequence # noqa # We 'bundle' isclass instead of using inspect as importing inspect is # fairly expensive (order of 10-15 ms for a modern machine in 2016) @@ -89,8 +90,27 @@ if PY2: res.data.update(d) # We blocked update, so we have to do it like this. return res + def just_warn(*args, **kw): # pragma: nocover + """ + We only warn on Python 3 because we are not aware of any concrete + consequences of not setting the cell on Python 2. + """ -else: + +else: # Python 3 and later. + from collections.abc import Mapping, Sequence # noqa + + def just_warn(*args, **kw): + """ + We only warn on Python 3 because we are not aware of any concrete + consequences of not setting the cell on Python 2. + """ + warnings.warn( + "Missing ctypes. Some features like bare super() or accessing " + "__class__ will not work with slots classes.", + RuntimeWarning, + stacklevel=2, + ) def isclass(klass): return isinstance(klass, type) @@ -113,30 +133,6 @@ def import_ctypes(): return ctypes -if not PY2: - - def just_warn(*args, **kw): - """ - We only warn on Python 3 because we are not aware of any concrete - consequences of not setting the cell on Python 2. - """ - warnings.warn( - "Missing ctypes. Some features like bare super() or accessing " - "__class__ will not work with slots classes.", - RuntimeWarning, - stacklevel=2, - ) - - -else: - - def just_warn(*args, **kw): # pragma: nocover - """ - We only warn on Python 3 because we are not aware of any concrete - consequences of not setting the cell on Python 2. - """ - - def make_set_closure_cell(): """ Moved into a function for testability. diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 54995d12..796d0d99 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -4,7 +4,7 @@ Tests for `attr._funcs`. from __future__ import absolute_import, division, print_function -from collections import Mapping, OrderedDict, Sequence +from collections import OrderedDict import pytest @@ -14,7 +14,7 @@ from hypothesis import strategies as st import attr from attr import asdict, assoc, astuple, evolve, fields, has -from attr._compat import TYPE +from attr._compat import TYPE, Mapping, Sequence, ordered_dict from attr.exceptions import AttrsAttributeNotFoundError from attr.validators import instance_of @@ -163,10 +163,10 @@ class TestAsDict(object): @given(simple_classes()) def test_asdict_preserve_order(self, cls): """ - Field order should be preserved when dumping to OrderedDicts. + Field order should be preserved when dumping to an ordered_dict. """ instance = cls() - dict_instance = asdict(instance, dict_factory=OrderedDict) + dict_instance = asdict(instance, dict_factory=ordered_dict) assert [a.name for a in fields(cls)] == list(dict_instance.keys()) diff --git a/tox.ini b/tox.ini index addf7519..640490ad 100644 --- a/tox.ini +++ b/tox.ini @@ -45,7 +45,7 @@ deps = black commands = flake8 src tests setup.py conftest.py docs/conf.py - black --check --verbose setup.py conftest.py src tests docs/conf.py + black --check setup.py conftest.py src tests docs/conf.py [testenv:pre-commit]