Skip to content

Commit

Permalink
Raise a better error
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Apr 4, 2023
1 parent 898764e commit 880644e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/attr/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,19 @@ def evolve(*args, **changes):
if args:
(inst,) = args
else:
try:
inst = changes.pop("inst")
except KeyError:
raise TypeError(
"evolve() missing 1 required positional argument: 'inst'"
)

warnings.warn(
"Passing the instance per keyword argument is deprecated and "
"will stop working in, or after, April 2024.",
DeprecationWarning,
stacklevel=2,
)
inst = changes.pop("inst")

cls = inst.__class__
attrs = fields(cls)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,10 @@ class C:
evolve(inst=C())

assert __file__ == wi.list[0].filename

def test_no_inst(self):
"""
Missing inst argument raises a TypeError like Python would.
"""
with pytest.raises(TypeError, match=r"evolve\(\) missing 1"):
evolve(x=1)

0 comments on commit 880644e

Please sign in to comment.