Skip to content

Commit 22ae847

Browse files
authored
Stop raising a deprecation warning on assoc (#1119)
* Stop warning about assoc & explain why * Fix tests
1 parent 5596c4f commit 22ae847

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

src/attr/_funcs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ def assoc(inst, **changes):
316316
"""
317317
Copy *inst* and apply *changes*.
318318
319+
This is different from `evolve` that applies the changes to the arguments
320+
that create the new instance.
321+
322+
`evolve`'s behavior is preferable, but there are `edge cases`_ where it
323+
doesn't work. Therefore `assoc` is deprecated, but will not be removed.
324+
325+
.. _`edge cases`: https://github.com/python-attrs/attrs/issues/251
326+
319327
:param inst: Instance of a class with *attrs* attributes.
320328
:param changes: Keyword changes in the new copy.
321329
@@ -331,13 +339,6 @@ def assoc(inst, **changes):
331339
This function will not be removed du to the slightly different approach
332340
compared to `attrs.evolve`.
333341
"""
334-
import warnings
335-
336-
warnings.warn(
337-
"assoc is deprecated and will be removed after 2018/01.",
338-
DeprecationWarning,
339-
stacklevel=2,
340-
)
341342
new = copy.copy(inst)
342343
attrs = fields(inst.__class__)
343344
for k, v in changes.items():

tests/test_funcs.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,7 @@ class C:
467467
pass
468468

469469
i1 = C()
470-
with pytest.deprecated_call():
471-
i2 = assoc(i1)
470+
i2 = assoc(i1)
472471

473472
assert i1 is not i2
474473
assert i1 == i2
@@ -479,8 +478,7 @@ def test_no_changes(self, C):
479478
No changes means a verbatim copy.
480479
"""
481480
i1 = C()
482-
with pytest.deprecated_call():
483-
i2 = assoc(i1)
481+
i2 = assoc(i1)
484482

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

500-
with pytest.deprecated_call():
501-
changed = assoc(original, **change_dict)
498+
changed = assoc(original, **change_dict)
502499

503500
for k, v in change_dict.items():
504501
assert getattr(changed, k) == v
@@ -527,22 +524,7 @@ class C:
527524
x = attr.ib()
528525
y = attr.ib()
529526

530-
with pytest.deprecated_call():
531-
assert C(3, 2) == assoc(C(1, 2), x=3)
532-
533-
def test_warning(self):
534-
"""
535-
DeprecationWarning points to the correct file.
536-
"""
537-
538-
@attr.s
539-
class C:
540-
x = attr.ib()
541-
542-
with pytest.warns(DeprecationWarning) as wi:
543-
assert C(2) == assoc(C(1), x=2)
544-
545-
assert __file__ == wi.list[0].filename
527+
assert C(3, 2) == assoc(C(1, 2), x=3)
546528

547529

548530
class TestEvolve:

0 commit comments

Comments
 (0)