From c422bf8041ed51d0df5e1485d1892f821e959cba Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 21 Mar 2022 10:29:58 +0100 Subject: [PATCH] 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=) --- changelog.d/939.breaking.rst | 2 ++ src/attr/_make.py | 17 ------------- tests/test_functional.py | 47 ++++++++---------------------------- 3 files changed, 12 insertions(+), 54 deletions(-) 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..6782fa9cc --- /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`` that can be used as a shortcut to set *eq* and *order* at the same time. 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..0f3a48c39 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,44 +641,19 @@ 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): + @pytest.mark.parametrize("slots", [True, False]) + @pytest.mark.parametrize("cmp", [True, False]) + def test_attrib_cmp_shortcut(self, slots, cmp): """ - Accessing Attribute.cmp raises a deprecation warning but returns True - if cmp is True, or eq and order are *both* effectively True. + Setting cmp on `attr.ib`s sets both eq and order. """ - # 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 + @attr.s(slots=slots) + class C: + x = attr.ib(cmp=cmp) - 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] - ) + 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):