From 290cf2a3f0b2aa0bf2c32d6f1ee1bbfe278122cb Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 19 Oct 2018 10:48:09 +0200 Subject: [PATCH] Quench a bunch of warnings --- setup.cfg | 1 + setup.py | 2 +- src/attr/_compat.py | 46 +++++++++++++++++++++------------------------ tests/test_funcs.py | 8 ++++---- tox.ini | 2 +- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9419a1572..9f536bba3 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 e382d1bd7..e6ea4b55d 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ "coverage", "hypothesis", "pympler", - "pytest", + "pytest<3.9", "six", "zope.interface", ], diff --git a/src/attr/_compat.py b/src/attr/_compat.py index 5bb065932..1a1db5734 100644 --- a/src/attr/_compat.py +++ b/src/attr/_compat.py @@ -20,6 +20,7 @@ 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 @@ def metadata_proxy(d): 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 54995d128..796d0d990 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function -from collections import Mapping, OrderedDict, Sequence +from collections import OrderedDict import pytest @@ -14,7 +14,7 @@ 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 @@ def test_roundtrip(self, cls, dict_class): @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 addf75194..640490adc 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]