Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop the deprecated Attribute.cmp #939

Merged
merged 3 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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.
17 changes: 0 additions & 17 deletions 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
47 changes: 10 additions & 37 deletions tests/test_functional.py
Expand Up @@ -12,7 +12,7 @@

import pytest

from hypothesis import assume, given
from hypothesis import given
from hypothesis.strategies import booleans

import attr
Expand All @@ -21,8 +21,6 @@
from attr._make import NOTHING, Attribute
from attr.exceptions import FrozenInstanceError

from .strategies import optional_bool


@attr.s
class C1:
Expand Down Expand Up @@ -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):
Expand Down