Skip to content

Commit 442199a

Browse files
committed
fix(ir): raise if Concrete.copy() receives unexpected arguments
1 parent 2e7fb76 commit 442199a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

ibis/common/grounds.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,7 @@ def argnames(self) -> tuple[str, ...]:
229229

230230
def copy(self, **overrides) -> Self:
231231
kwargs = dict(zip(self.__argnames__, self.__args__))
232+
if unknown_args := overrides.keys() - kwargs.keys():
233+
raise AttributeError(f"Unexpected arguments: {unknown_args}")
232234
kwargs.update(overrides)
233235
return self.__recreate__(kwargs)

ibis/common/tests/test_grounds.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,21 +616,39 @@ class Test(Annotable):
616616
assert Test(1, 2, a=3, b=4, c=5).options == {"a": 3, "b": 4, "c": 5}
617617

618618

619-
def test_concrete_copy_with_variadic_argument():
620-
class Test(Annotable):
619+
def test_copy_with_variadic_argument():
620+
class Foo(Annotable):
621+
a = is_int
622+
b = is_int
623+
args = varargs(is_int)
624+
625+
class Bar(Concrete):
621626
a = is_int
622627
b = is_int
623628
args = varargs(is_int)
624629

625-
t = Test(1, 2, 3, 4, 5)
630+
for t in [Foo(1, 2, 3, 4, 5), Bar(1, 2, 3, 4, 5)]:
631+
assert t.a == 1
632+
assert t.b == 2
633+
assert t.args == (3, 4, 5)
634+
635+
u = t.copy(a=6, args=(8, 9, 10))
636+
assert u.a == 6
637+
assert u.b == 2
638+
assert u.args == (8, 9, 10)
639+
640+
641+
def test_concrete_copy_with_unknown_argument_raise():
642+
class Bar(Concrete):
643+
a = is_int
644+
b = is_int
645+
646+
t = Bar(1, 2)
626647
assert t.a == 1
627648
assert t.b == 2
628-
assert t.args == (3, 4, 5)
629649

630-
u = t.copy(a=6, args=(8, 9, 10))
631-
assert u.a == 6
632-
assert u.b == 2
633-
assert u.args == (8, 9, 10)
650+
with pytest.raises(AttributeError, match="Unexpected arguments"):
651+
t.copy(c=3, d=4)
634652

635653

636654
def test_concrete_pickling_variadic_arguments():

0 commit comments

Comments
 (0)