Skip to content

Commit

Permalink
Stop raising a deprecation warning on assoc (#1119)
Browse files Browse the repository at this point in the history
* Stop warning about assoc & explain why

* Fix tests
  • Loading branch information
hynek committed Apr 4, 2023
1 parent 5596c4f commit 22ae847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
15 changes: 8 additions & 7 deletions src/attr/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ def assoc(inst, **changes):
"""
Copy *inst* and apply *changes*.
This is different from `evolve` that applies the changes to the arguments
that create the new instance.
`evolve`'s behavior is preferable, but there are `edge cases`_ where it
doesn't work. Therefore `assoc` is deprecated, but will not be removed.
.. _`edge cases`: https://github.com/python-attrs/attrs/issues/251
:param inst: Instance of a class with *attrs* attributes.
:param changes: Keyword changes in the new copy.
Expand All @@ -331,13 +339,6 @@ def assoc(inst, **changes):
This function will not be removed du to the slightly different approach
compared to `attrs.evolve`.
"""
import warnings

warnings.warn(
"assoc is deprecated and will be removed after 2018/01.",
DeprecationWarning,
stacklevel=2,
)
new = copy.copy(inst)
attrs = fields(inst.__class__)
for k, v in changes.items():
Expand Down
26 changes: 4 additions & 22 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ class C:
pass

i1 = C()
with pytest.deprecated_call():
i2 = assoc(i1)
i2 = assoc(i1)

assert i1 is not i2
assert i1 == i2
Expand All @@ -479,8 +478,7 @@ def test_no_changes(self, C):
No changes means a verbatim copy.
"""
i1 = C()
with pytest.deprecated_call():
i2 = assoc(i1)
i2 = assoc(i1)

assert i1 is not i2
assert i1 == i2
Expand All @@ -497,8 +495,7 @@ def test_change(self, C, data):
chosen_names = data.draw(st.sets(st.sampled_from(field_names)))
change_dict = {name: data.draw(st.integers()) for name in chosen_names}

with pytest.deprecated_call():
changed = assoc(original, **change_dict)
changed = assoc(original, **change_dict)

for k, v in change_dict.items():
assert getattr(changed, k) == v
Expand Down Expand Up @@ -527,22 +524,7 @@ class C:
x = attr.ib()
y = attr.ib()

with pytest.deprecated_call():
assert C(3, 2) == assoc(C(1, 2), x=3)

def test_warning(self):
"""
DeprecationWarning points to the correct file.
"""

@attr.s
class C:
x = attr.ib()

with pytest.warns(DeprecationWarning) as wi:
assert C(2) == assoc(C(1), x=2)

assert __file__ == wi.list[0].filename
assert C(3, 2) == assoc(C(1, 2), x=3)


class TestEvolve:
Expand Down

0 comments on commit 22ae847

Please sign in to comment.