Add advice for fixing RUF008 when mutability is not desired (#8853)

This commit is contained in:
Samuel Searles-Bryant 2023-11-27 15:27:22 +00:00 committed by GitHub
parent 0202a49297
commit 1f14d9a9f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -20,13 +20,15 @@ use crate::rules::ruff::rules::helpers::{
/// changed in one instance, as those changes will unexpectedly affect all /// changed in one instance, as those changes will unexpectedly affect all
/// other instances. /// other instances.
/// ///
/// When mutable value are intended, they should be annotated with /// When mutable values are intended, they should be annotated with
/// `typing.ClassVar`. /// `typing.ClassVar`. When mutability is not required, values should be
/// immutable types, like `tuple` or `frozenset`.
/// ///
/// ## Examples /// ## Examples
/// ```python /// ```python
/// class A: /// class A:
/// mutable_default: list[int] = [] /// mutable_default: list[int] = []
/// immutable_default: list[int] = []
/// ``` /// ```
/// ///
/// Use instead: /// Use instead:
@ -36,6 +38,7 @@ use crate::rules::ruff::rules::helpers::{
/// ///
/// class A: /// class A:
/// mutable_default: ClassVar[list[int]] = [] /// mutable_default: ClassVar[list[int]] = []
/// immutable_default: tuple[int, ...] = ()
/// ``` /// ```
#[violation] #[violation]
pub struct MutableClassDefault; pub struct MutableClassDefault;