Skip to content

Commit c422bf8

Browse files
authored
Drop the deprecated Attribute.cmp (#939)
* Drop the deprecated Attribute.cmp This has nothing to do with the cmp argument to attr.s/define which have been undeprecated. * Add newsfragment * Add test for attr.ib(cmp=)
1 parent 980c8b0 commit c422bf8

File tree

3 files changed

+12
-54
lines changed

3 files changed

+12
-54
lines changed

changelog.d/939.breaking.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The deprecated ``cmp`` attribute of ``attrs.Attribute`` has been removed.
2+
This does not affect the *cmp* argument to ``attr.s`` that can be used as a shortcut to set *eq* and *order* at the same time.

src/attr/_make.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# SPDX-License-Identifier: MIT
22

3-
43
import copy
54
import linecache
65
import sys
76
import typing
8-
import warnings
97

108
from operator import itemgetter
119

@@ -1093,12 +1091,6 @@ def _add_method_dunders(self, method):
10931091
return method
10941092

10951093

1096-
_CMP_DEPRECATION = (
1097-
"The usage of `cmp` is deprecated and will be removed on or after "
1098-
"2021-06-01. Please use `eq` and `order` instead."
1099-
)
1100-
1101-
11021094
def _determine_attrs_eq_order(cmp, eq, order, default_eq):
11031095
"""
11041096
Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
@@ -2594,15 +2586,6 @@ def from_counting_attr(cls, name, ca, type=None):
25942586
**inst_dict
25952587
)
25962588

2597-
@property
2598-
def cmp(self):
2599-
"""
2600-
Simulate the presence of a cmp attribute and warn.
2601-
"""
2602-
warnings.warn(_CMP_DEPRECATION, DeprecationWarning, stacklevel=2)
2603-
2604-
return self.eq and self.order
2605-
26062589
# Don't use attr.evolve since fields(Attribute) doesn't work
26072590
def evolve(self, **changes):
26082591
"""

tests/test_functional.py

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import pytest
1414

15-
from hypothesis import assume, given
15+
from hypothesis import given
1616
from hypothesis.strategies import booleans
1717

1818
import attr
@@ -21,8 +21,6 @@
2121
from attr._make import NOTHING, Attribute
2222
from attr.exceptions import FrozenInstanceError
2323

24-
from .strategies import optional_bool
25-
2624

2725
@attr.s
2826
class C1:
@@ -643,44 +641,19 @@ class C:
643641

644642
assert ei.value.args[0] in possible_errors
645643

646-
@given(cmp=optional_bool, eq=optional_bool, order=optional_bool)
647-
def test_cmp_deprecated_attribute(self, cmp, eq, order):
644+
@pytest.mark.parametrize("slots", [True, False])
645+
@pytest.mark.parametrize("cmp", [True, False])
646+
def test_attrib_cmp_shortcut(self, slots, cmp):
648647
"""
649-
Accessing Attribute.cmp raises a deprecation warning but returns True
650-
if cmp is True, or eq and order are *both* effectively True.
648+
Setting cmp on `attr.ib`s sets both eq and order.
651649
"""
652-
# These cases are invalid and raise a ValueError.
653-
assume(cmp is None or (eq is None and order is None))
654-
assume(not (eq is False and order is True))
655-
656-
if cmp is not None:
657-
rv = cmp
658-
elif eq is True or eq is None:
659-
rv = order is None or order is True
660-
elif cmp is None and eq is None and order is None:
661-
rv = True
662-
elif cmp is None or eq is None:
663-
rv = False
664-
else:
665-
pytest.fail(
666-
"Unexpected state: cmp=%r eq=%r order=%r" % (cmp, eq, order)
667-
)
668-
669-
with pytest.deprecated_call() as dc:
670-
671-
@attr.s
672-
class C:
673-
x = attr.ib(cmp=cmp, eq=eq, order=order)
674650

675-
assert rv == attr.fields(C).x.cmp
676-
677-
(w,) = dc.list
651+
@attr.s(slots=slots)
652+
class C:
653+
x = attr.ib(cmp=cmp)
678654

679-
assert (
680-
"The usage of `cmp` is deprecated and will be removed on or after "
681-
"2021-06-01. Please use `eq` and `order` instead."
682-
== w.message.args[0]
683-
)
655+
assert cmp is attr.fields(C).x.eq
656+
assert cmp is attr.fields(C).x.order
684657

685658
@pytest.mark.parametrize("slots", [True, False])
686659
def test_no_setattr_if_validate_without_validators(self, slots):

0 commit comments

Comments
 (0)