Skip to content

Preserve default factories when pickling munches - #110

Open
vitalivo wants to merge 1 commit into
Infinidat:developfrom
vitalivo:fix/pickle-default-factory
Open

vitalivo wants to merge 1 commit into
Infinidat:developfrom
vitalivo:fix/pickle-default-factory

Conversation

@vitalivo

Copy link
Copy Markdown

This replaces #109, which was accidentally closed and its source fork deleted. The implementation is unchanged; the original discussion and reviews remain linked there.


Pickling a DefaultFactoryMunch(list, existing=[1]) currently discards default_factory. Accessing a missing attribute on the restored object then raises RecursionError, because looking up the missing factory invokes __missing__ again.

Store the factory alongside the dictionary state and restore it before the items. This also preserves nested RecursiveMunch behavior. Regression tests cover all six pickle protocols, independent default values, and recursive factories.

Validation: 122 tests pass on Python 3.11 with PyYAML. The six original factory regressions failed before the fix. The optional module doctests have four pre-existing failures (dictionary ordering, multiline output, and the old yaml.load call); the same four failures were verified on unchanged HEAD.

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.

1 participant