Skip to content

Commit

Permalink
[flake8-self] Ignore _name_ and _value_ (#5663)
Browse files Browse the repository at this point in the history
## Summary

`Enum._name_` and `Enum._value_` are so named to prevent conflicts. See
<https://docs.python.org/3/library/enum.html#supported-sunder-names>.

## Test Plan

Tests for `ignore-names` already exist.
  • Loading branch information
monosans authored Jul 10, 2023
1 parent b8a6ce4 commit 14f2158
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/ruff/src/rules/flake8_self/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ use serde::{Deserialize, Serialize};

use ruff_macros::{CacheKey, CombineOptions, ConfigurationOptions};

// By default, ignore the `namedtuple` methods and attributes, which are underscore-prefixed to
// prevent conflicts with field names.
const IGNORE_NAMES: [&str; 5] = ["_make", "_asdict", "_replace", "_fields", "_field_defaults"];
// By default, ignore the `namedtuple` methods and attributes, as well as the
// _sunder_ names in Enum, which are underscore-prefixed to prevent conflicts
// with field names.
const IGNORE_NAMES: [&str; 7] = [
"_make",
"_asdict",
"_replace",
"_fields",
"_field_defaults",
"_name_",
"_value_",
];

#[derive(
Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions, CombineOptions,
Expand All @@ -19,7 +28,7 @@ const IGNORE_NAMES: [&str; 5] = ["_make", "_asdict", "_replace", "_fields", "_fi
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Options {
#[option(
default = r#"["_make", "_asdict", "_replace", "_fields", "_field_defaults"]"#,
default = r#"["_make", "_asdict", "_replace", "_fields", "_field_defaults", "_name_", "_value_"]"#,
value_type = "list[str]",
example = r#"
ignore-names = ["_new"]
Expand Down

0 comments on commit 14f2158

Please sign in to comment.