Skip to content

Comments

Save and restore working_set in include_subclasses#726

Open
bysiber wants to merge 1 commit intopython-attrs:mainfrom
bysiber:fix-include-subclasses-working-set
Open

Save and restore working_set in include_subclasses#726
bysiber wants to merge 1 commit intopython-attrs:mainfrom
bysiber:fix-include-subclasses-working-set

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 22, 2026

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

When include_subclasses is called from within a structure hook
factory (which is itself invoked during make_dict_structure_fn),
it would overwrite already_generating.working_set with its own
set and then reset it to an empty set. This caused the outer
make_dict_structure_fn to fail with AttributeError when trying
to clean up its working_set.

Now the existing working_set is saved before the loop and restored
after, so nested calls work correctly.
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 22, 2026

Merging this PR will not alter performance

✅ 54 untouched benchmarks


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

Open in CodSpeed

@Tinche
Copy link
Member

Tinche commented Feb 22, 2026

Hello, I believe this is already being fixed in #722 , right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: working_set when using include_subclasses inside struct_hook_factory

2 participants