Commit 42f1c6f
[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: D72111785
fbshipit-source-id: fb6d3e1c7fab3f3d2452d6335233fec767551eef1 parent 528cb73 commit 42f1c6f
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments