cattrs icon indicating copy to clipboard operation
cattrs copied to clipboard

Save and restore working_set in include_subclasses

Open bysiber opened this issue 9 months ago • 2 comments

When include_subclasses is called from within a structure hook factory (which itself runs during make_dict_structure_fn), it overwrites already_generating.working_set with its own set and then resets it to an empty set. This breaks the outer make_dict_structure_fn which still expects to clean up its own working_set, causing AttributeError: working_set.

The fix saves the existing working_set before the loop and restores it after, so nested generation contexts work correctly.

Added a regression test that reproduces the exact scenario from #721.

Fixes #721

bysiber avatar Feb 22 '26 01:02 bysiber

Merging this PR will not alter performance

✅ 54 untouched benchmarks


Comparing bysiber:fix-include-subclasses-working-set (fc8449a) with main (fd887b7)

Open in CodSpeed

codspeed[bot] avatar Feb 22 '26 10:02 codspeed[bot]

Hello, I believe this is already being fixed in https://github.com/python-attrs/cattrs/pull/722 , right?

Tinche avatar Feb 22 '26 10:02 Tinche