Closed pixeebot[bot] closed 6 months ago
I'm confident in this change, but I'm not a maintainer of this project. Do you see any reason not to merge it?
If this change was not helpful, or you have suggestions for improvements, please let me know!
Just a friendly ping to remind you about this change. If there are concerns about it, we'd love to hear about them!
This change may not be a priority right now, so I'll close it. If there was something I could have done better, please let me know!
You can also customize me to make sure I'm working with you in the way you want.
When defining a Python dataclass it is not safe to use mutable datatypes (such as
list
,dict
, orset
) as defaults for the attributes. This is because the defined attribute will be shared by all instances of the dataclass type. Using such a mutable default will ultimately result in aValueError
at runtime. This codemod updates attributes ofdataclasses.dataclass
with mutable defaults to usedataclasses.field
instead. The dataclass documentation providesmore details about why usingfield(default_factory=...)
is the recommended pattern.Our changes look something like this:
More reading
* [https://docs.python.org/3/library/dataclasses.html#mutable-default-values](https://docs.python.org/3/library/dataclasses.html#mutable-default-values)Powered by: pixeebot (codemod ID: pixee:python/fix-dataclass-defaults)