Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[codemod][py3.12] Convert dataclasses mutable default values to use d…
…efault_factory Summary: As of [Python 3.11](https://docs.python.org/3.11/whatsnew/3.11.html#dataclasses), dataclasses now only allow defaults that are hashable. Using mutable (non-hashable) default values under Python 3.11+ will cause a runtime error: ``` ValueError: mutable default <class 'problematic.ClassName'> for field <field> is not allowed: use default_factory ``` This codemod attempts to automatically convert mutable defaults to use `default_factory` NOTE: The change is not semantically equivalent to before the change. Before, all dataclass instances with a mutable default value were sharing the same instance. This change results each dataclass instance using a new instance of the mutable value. It is likely that the before state was a latent bug, but it's still a behavior change! Reviewed By: itamaro Differential Revision: D70448655 fbshipit-source-id: 09b49467f1fe54f5ea9669de401f4f9cceadc06e
- Loading branch information