Skip to content

Commit

Permalink
Quench a bunch of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Oct 19, 2018
1 parent dcfcf5e commit 290cf2a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addopts = -ra
testpaths = tests
filterwarnings =
once::Warning
ignore:::pympler[.*]


[isort]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"coverage",
"hypothesis",
"pympler",
"pytest",
"pytest<3.9",
"six",
"zope.interface",
],
Expand Down
46 changes: 21 additions & 25 deletions src/attr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import absolute_import, division, print_function

from collections import Mapping, OrderedDict, Sequence
from collections import OrderedDict

import pytest

Expand All @@ -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

Expand Down Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 290cf2a

Please sign in to comment.