| 2351 | assert not gc.is_tracked(res) |
| 2352 | |
| 2353 | def test_replace_reference_counts(self, replace): |
| 2354 | class Test(msgspec.Struct): |
| 2355 | x: Any |
| 2356 | y: int |
| 2357 | |
| 2358 | x = object() |
| 2359 | t = Test(x, 1) |
| 2360 | |
| 2361 | x_count = sys.getrefcount(x) |
| 2362 | |
| 2363 | t2 = replace(t) |
| 2364 | assert sys.getrefcount(x) == x_count + 1 |
| 2365 | del t2 |
| 2366 | |
| 2367 | t2 = replace(t, x=None) |
| 2368 | assert sys.getrefcount(x) == x_count |
| 2369 | del t2 |
| 2370 | |
| 2371 | t2 = replace(t, y=2) |
| 2372 | assert sys.getrefcount(x) == x_count + 1 |
| 2373 | del t2 |
| 2374 | |
| 2375 | x2 = object() |
| 2376 | x2_count = sys.getrefcount(x2) |
| 2377 | t2 = replace(t, x=x2) |
| 2378 | assert sys.getrefcount(x) == x_count |
| 2379 | assert sys.getrefcount(x2) == x2_count + 1 |
| 2380 | del t2 |
| 2381 | |
| 2382 | def test_replace_calls_post_init(self, replace): |
| 2383 | count = 0 |