(self)
| 2610 | |
| 2611 | class TestPostInit: |
| 2612 | def test_post_init(self): |
| 2613 | called = False |
| 2614 | singleton = object() |
| 2615 | |
| 2616 | class Ex(Struct): |
| 2617 | x: int |
| 2618 | |
| 2619 | def __post_init__(self): |
| 2620 | nonlocal called |
| 2621 | called = True |
| 2622 | return singleton |
| 2623 | |
| 2624 | Ex(1) |
| 2625 | assert called |
| 2626 | # Return value is decref'd |
| 2627 | assert sys.getrefcount(singleton) <= 2 # 1 for ref, 1 for call |
| 2628 | |
| 2629 | def test_post_init_errors(self): |
| 2630 | class Ex(Struct): |