From 8004c7835ceea150833abc145d05f2323ac00e05 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 21 Mar 2022 08:56:29 +0100 Subject: [PATCH 1/3] Drop the deprecated Attribute.cmp This has nothing to do with the cmp argument to attr.s/define which have been undeprecated. --- src/attr/_make.py | 17 ---------------- tests/test_functional.py | 43 +--------------------------------------- 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/src/attr/_make.py b/src/attr/_make.py index 0b974f30b..ab3f0bedc 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -1,11 +1,9 @@ # SPDX-License-Identifier: MIT - import copy import linecache import sys import typing -import warnings from operator import itemgetter @@ -1093,12 +1091,6 @@ def _add_method_dunders(self, method): return method -_CMP_DEPRECATION = ( - "The usage of `cmp` is deprecated and will be removed on or after " - "2021-06-01. Please use `eq` and `order` instead." -) - - def _determine_attrs_eq_order(cmp, eq, order, default_eq): """ Validate the combination of *cmp*, *eq*, and *order*. Derive the effective @@ -2594,15 +2586,6 @@ def from_counting_attr(cls, name, ca, type=None): **inst_dict ) - @property - def cmp(self): - """ - Simulate the presence of a cmp attribute and warn. - """ - warnings.warn(_CMP_DEPRECATION, DeprecationWarning, stacklevel=2) - - return self.eq and self.order - # Don't use attr.evolve since fields(Attribute) doesn't work def evolve(self, **changes): """ diff --git a/tests/test_functional.py b/tests/test_functional.py index c6a808438..3d01c3c87 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -12,7 +12,7 @@ import pytest -from hypothesis import assume, given +from hypothesis import given from hypothesis.strategies import booleans import attr @@ -21,8 +21,6 @@ from attr._make import NOTHING, Attribute from attr.exceptions import FrozenInstanceError -from .strategies import optional_bool - @attr.s class C1: @@ -643,45 +641,6 @@ class C: assert ei.value.args[0] in possible_errors - @given(cmp=optional_bool, eq=optional_bool, order=optional_bool) - def test_cmp_deprecated_attribute(self, cmp, eq, order): - """ - Accessing Attribute.cmp raises a deprecation warning but returns True - if cmp is True, or eq and order are *both* effectively True. - """ - # These cases are invalid and raise a ValueError. - assume(cmp is None or (eq is None and order is None)) - assume(not (eq is False and order is True)) - - if cmp is not None: - rv = cmp - elif eq is True or eq is None: - rv = order is None or order is True - elif cmp is None and eq is None and order is None: - rv = True - elif cmp is None or eq is None: - rv = False - else: - pytest.fail( - "Unexpected state: cmp=%r eq=%r order=%r" % (cmp, eq, order) - ) - - with pytest.deprecated_call() as dc: - - @attr.s - class C: - x = attr.ib(cmp=cmp, eq=eq, order=order) - - assert rv == attr.fields(C).x.cmp - - (w,) = dc.list - - assert ( - "The usage of `cmp` is deprecated and will be removed on or after " - "2021-06-01. Please use `eq` and `order` instead." - == w.message.args[0] - ) - @pytest.mark.parametrize("slots", [True, False]) def test_no_setattr_if_validate_without_validators(self, slots): """ From 398bb1697a2141f7200c887ab9455df2ad3253b2 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 21 Mar 2022 09:00:09 +0100 Subject: [PATCH 2/3] Add newsfragment --- changelog.d/939.breaking.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/939.breaking.rst diff --git a/changelog.d/939.breaking.rst b/changelog.d/939.breaking.rst new file mode 100644 index 000000000..b0e904c53 --- /dev/null +++ b/changelog.d/939.breaking.rst @@ -0,0 +1,2 @@ +The deprecated ``cmp`` attribute of ``attrs.Attribute`` has been removed. +This does not affect the *cmp* argument to ``attr.s``/``define`` which can be used as a shortcut to set *eq* and *order* at the same time. From 81bab846debdece907b254afc2508f40c613b8d7 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 21 Mar 2022 09:22:03 +0100 Subject: [PATCH 3/3] Add test for attr.ib(cmp=) --- changelog.d/939.breaking.rst | 2 +- tests/test_functional.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/changelog.d/939.breaking.rst b/changelog.d/939.breaking.rst index b0e904c53..6782fa9cc 100644 --- a/changelog.d/939.breaking.rst +++ b/changelog.d/939.breaking.rst @@ -1,2 +1,2 @@ The deprecated ``cmp`` attribute of ``attrs.Attribute`` has been removed. -This does not affect the *cmp* argument to ``attr.s``/``define`` which can be used as a shortcut to set *eq* and *order* at the same time. +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. diff --git a/tests/test_functional.py b/tests/test_functional.py index 3d01c3c87..0f3a48c39 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -641,6 +641,20 @@ class C: assert ei.value.args[0] in possible_errors + @pytest.mark.parametrize("slots", [True, False]) + @pytest.mark.parametrize("cmp", [True, False]) + def test_attrib_cmp_shortcut(self, slots, cmp): + """ + Setting cmp on `attr.ib`s sets both eq and order. + """ + + @attr.s(slots=slots) + class C: + x = attr.ib(cmp=cmp) + + assert cmp is attr.fields(C).x.eq + assert cmp is attr.fields(C).x.order + @pytest.mark.parametrize("slots", [True, False]) def test_no_setattr_if_validate_without_validators(self, slots): """