Commit a883719
[codemod][py3.12] Convert dataclasses mutable default values to use default_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: D72541748
fbshipit-source-id: 32a57309ed267f52813d54bb647e4ca5f9c67c581 parent 42f1c6f commit a883719
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
| 57 | + | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
0 commit comments