Skip to content

Commit f520d9a

Browse files
authored
Only soft-deprecate hash (#1330)
* Only soft-deprecate hash Given the amount of warnings in the eco-system, make the deprection soft. We won't remove it. * news fragment
1 parent 69d6fd1 commit f520d9a

3 files changed

Lines changed: 3 additions & 44 deletions

File tree

changelog.d/1330.deprecation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Given the amount of warnings from the broader ecosystem, we've decided to only soft-deprecate the *hash* argument to `@define` / `@attr.s`.
2+
Please don't use it in new code, but we don't intend to remove it anymore.

src/attr/_make.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,7 @@ def attrs(
12841284

12851285
eq_, order_ = _determine_attrs_eq_order(cmp, eq, order, None)
12861286

1287-
# hash is deprecated & unsafe_hash takes precedence due to PEP 681.
1288-
if hash is not None:
1289-
import warnings
1290-
1291-
warnings.warn(
1292-
DeprecationWarning(
1293-
"The `hash` argument is deprecated in favor of `unsafe_hash` and will be removed in or after August 2025."
1294-
),
1295-
stacklevel=2,
1296-
)
1287+
# unsafe_hash takes precedence due to PEP 681.
12971288
if unsafe_hash is not None:
12981289
hash = unsafe_hash
12991290

@@ -2864,19 +2855,6 @@ def make_class(
28642855
True,
28652856
)
28662857

2867-
hash = attributes_arguments.pop("hash", _SENTINEL)
2868-
if hash is not _SENTINEL:
2869-
import warnings
2870-
2871-
warnings.warn(
2872-
DeprecationWarning(
2873-
"The `hash` argument is deprecated in favor of `unsafe_hash` and will be removed in or after August 2025."
2874-
),
2875-
stacklevel=2,
2876-
)
2877-
2878-
attributes_arguments["unsafe_hash"] = hash
2879-
28802858
cls = _attrs(these=cls_dict, **attributes_arguments)(type_)
28812859
# Only add type annotations now or "_attrs()" will complain:
28822860
cls.__annotations__ = {

tests/test_make.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ def _with_and_without_validation(request):
6969
attr.validators.set_disabled(False)
7070

7171

72-
@pytest.mark.parametrize("hash", [True, False])
73-
def test_hash_is_deprecated(hash):
74-
"""
75-
Passing anything else than None to hash raises a deprecation warning.
76-
"""
77-
with pytest.deprecated_call():
78-
79-
@attr.s(hash=hash)
80-
class C:
81-
pass
82-
83-
8472
class TestCountingAttr:
8573
"""
8674
Tests for `attr`.
@@ -1223,15 +1211,6 @@ def test_annotations_resolve(self):
12231211
assert attr.fields(C).a.type is bool
12241212
assert {"a": "bool"} == C.__annotations__
12251213

1226-
@pytest.mark.parametrize("hash", [True, False])
1227-
def test_hash_is_deprecated(self, hash):
1228-
"""
1229-
Passing anything else than None to hash raises a deprecation warning.
1230-
"""
1231-
with pytest.deprecated_call():
1232-
1233-
make_class("CH", {}, hash=hash)
1234-
12351214

12361215
class TestFields:
12371216
"""

0 commit comments

Comments
 (0)