From 22ae8473fb88d6e585b05c709e81e1a46398a649 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Tue, 4 Apr 2023 08:50:55 +0200 Subject: [PATCH] Stop raising a deprecation warning on assoc (#1119) * Stop warning about assoc & explain why * Fix tests --- src/attr/_funcs.py | 15 ++++++++------- tests/test_funcs.py | 26 ++++---------------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/attr/_funcs.py b/src/attr/_funcs.py index fe110739b..7ee1c910f 100644 --- a/src/attr/_funcs.py +++ b/src/attr/_funcs.py @@ -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. @@ -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(): diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 9f6845647..bee36706e 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -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 @@ -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 @@ -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 @@ -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: