| 591 | Test(1, 2, e=5) |
| 592 | |
| 593 | def test_init_kw_only(self): |
| 594 | class Test(Struct, kw_only=True): |
| 595 | a: int |
| 596 | b: float = 2.0 |
| 597 | c: int = 3 |
| 598 | |
| 599 | assert as_tuple(Test(a=1)) == (1, 2.0, 3) |
| 600 | assert as_tuple(Test(a=1, b=4.0)) == (1, 4.0, 3) |
| 601 | assert as_tuple(Test(a=1, c=4)) == (1, 2.0, 4) |
| 602 | assert as_tuple(Test(a=1, b=4.0, c=5)) == (1, 4.0, 5) |
| 603 | |
| 604 | with pytest.raises(TypeError, match="Missing required argument 'a'"): |
| 605 | Test() |
| 606 | |
| 607 | with pytest.raises(TypeError, match="Extra positional arguments provided"): |
| 608 | Test(1) |
| 609 | |
| 610 | with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"): |
| 611 | Test(a=1, e=5) |
| 612 | |
| 613 | def test_init_kw_only_mixed(self): |
| 614 | class Base(Struct, kw_only=True): |