From 8bf233af6be853d6014e39339677df8a9689e397 Mon Sep 17 00:00:00 2001 From: Dani Alcala <112832187+clavedeluna@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:18:06 -0300 Subject: [PATCH] Update src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md Co-authored-by: Dan D'Avella --- src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md b/src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md index ddb624e62..926cee101 100644 --- a/src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md +++ b/src/core_codemods/docs/pixee_python_fix-dataclass-defaults.md @@ -1,4 +1,4 @@ -This codemod will fix instances of `dataclasses.dataclass` that define default lists, sets, or dicts which raise a runtime `ValueError`. The [dataclass documentation](https://docs.python.org/3/library/dataclasses.html#mutable-default-values) provides a clear explanation of why this code is disallowed and explains how to use `field(default_factory=...)` instead. +When defining a Python dataclass it is not safe to use mutable datatypes (such as `list`, `dict`, or `set`) 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 a `ValueError` at runtime. This codemod updates attributes of `dataclasses.dataclass` with mutable defaults to use `dataclasses.field` instead. The [dataclass documentation](https://docs.python.org/3/library/dataclasses.html#mutable-default-values) providesmore details about why using `field(default_factory=...)` is the recommended pattern. Our changes look something like this: