From 54ddb9f09af0db9741a009c51479aa76ab46fa59 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 00:56:39 +0530 Subject: [PATCH 01/10] [flake8-pyi] Implement PYI062 --- .../test/fixtures/flake8_pyi/PYI062.py | 9 +++ .../test/fixtures/flake8_pyi/PYI062.pyi | 9 +++ .../src/checkers/ast/analyze/expression.rs | 15 ++++ crates/ruff_linter/src/codes.rs | 1 + .../ruff_linter/src/rules/flake8_pyi/mod.rs | 2 + .../rules/duplicate_literal_member.rs | 68 +++++++++++++++++++ .../src/rules/flake8_pyi/rules/mod.rs | 2 + ...__flake8_pyi__tests__PYI062_PYI062.py.snap | 42 ++++++++++++ ..._flake8_pyi__tests__PYI062_PYI062.pyi.snap | 42 ++++++++++++ .../src/analyze/typing.rs | 38 +++++++++++ crates/ruff_python_semantic/src/model.rs | 9 +++ 11 files changed, 237 insertions(+) create mode 100644 crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py create mode 100644 crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi create mode 100644 crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs create mode 100644 crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap create mode 100644 crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py new file mode 100644 index 0000000000000..967f3cdb5ea08 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py @@ -0,0 +1,9 @@ +from typing import Literal + +x: Literal[True, False, True, False] # PYI062 twice here + +y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 + +z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + +n: Literal["No", "duplicates", "here", 1, "1"] diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi new file mode 100644 index 0000000000000..28db68d785934 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi @@ -0,0 +1,9 @@ +from typing import Literal + +x: Literal[True, False, True, False] # PY062 twice here + +y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 + +z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + +n: Literal["No", "duplicates", "here", 1, "1"] diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 36a9b21e8f793..a659518da25b2 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -98,6 +98,13 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { } } + // Ex) Literal[...] + if checker.enabled(Rule::DuplicateLiteralMember) { + if !checker.semantic.in_nested_literal() { + flake8_pyi::rules::duplicate_literal_member(checker, expr); + } + } + if checker.enabled(Rule::NeverUnion) { ruff::rules::never_union(checker, expr); } @@ -1194,6 +1201,14 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { ruff::rules::never_union(checker, expr); } + // Avoid duplicate checks if the parent is a literal, since this rule already + // traverses nested literals. + if checker.enabled(Rule::DuplicateLiteralMember) { + if !checker.semantic.in_nested_literal() { + flake8_pyi::rules::duplicate_literal_member(checker, expr); + } + } + // Avoid duplicate checks if the parent is a union, since these rules already // traverse nested unions. if !checker.semantic.in_nested_union() { diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 07f610a9cc078..f4e308c512a82 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -808,6 +808,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Pyi, "055") => (RuleGroup::Stable, rules::flake8_pyi::rules::UnnecessaryTypeUnion), (Flake8Pyi, "056") => (RuleGroup::Stable, rules::flake8_pyi::rules::UnsupportedMethodCallOnAll), (Flake8Pyi, "058") => (RuleGroup::Stable, rules::flake8_pyi::rules::GeneratorReturnFromIterMethod), + (Flake8Pyi, "062") => (RuleGroup::Stable, rules::flake8_pyi::rules::DuplicateLiteralMember), // flake8-pytest-style (Flake8PytestStyle, "001") => (RuleGroup::Stable, rules::flake8_pytest_style::rules::PytestFixtureIncorrectParenthesesStyle), diff --git a/crates/ruff_linter/src/rules/flake8_pyi/mod.rs b/crates/ruff_linter/src/rules/flake8_pyi/mod.rs index 004aacd280bfe..817af3f837fa4 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/mod.rs @@ -33,6 +33,8 @@ mod tests { #[test_case(Rule::CustomTypeVarReturnType, Path::new("PYI019.pyi"))] #[test_case(Rule::DocstringInStub, Path::new("PYI021.py"))] #[test_case(Rule::DocstringInStub, Path::new("PYI021.pyi"))] + #[test_case(Rule::DuplicateLiteralMember, Path::new("PYI062.py"))] + #[test_case(Rule::DuplicateLiteralMember, Path::new("PYI062.pyi"))] #[test_case(Rule::DuplicateUnionMember, Path::new("PYI016.py"))] #[test_case(Rule::DuplicateUnionMember, Path::new("PYI016.pyi"))] #[test_case(Rule::EllipsisInNonEmptyClassBody, Path::new("PYI013.py"))] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs new file mode 100644 index 0000000000000..b68f441f54a69 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -0,0 +1,68 @@ +use std::collections::HashSet; + +use rustc_hash::FxHashSet; + +use ruff_diagnostics::{Diagnostic, FixAvailability, Violation}; +use ruff_macros::{derive_message_formats, violation}; +use ruff_python_ast::comparable::ComparableExpr; +use ruff_python_ast::Expr; +use ruff_python_semantic::analyze::typing::traverse_literal; +use ruff_text_size::Ranged; + +use crate::checkers::ast::Checker; + +/// ## What it does +/// Checks for duplicate literal members. +/// +/// ## Why is this bad? +/// Duplicate literal members are redundant and should be removed. +/// +/// ## Example +/// ```python +/// foo: Literal[True, False, True] +/// ``` +/// +/// Use instead: +/// ```python +/// foo: Literal[True, False] +/// ``` +/// +/// ## References +/// - [Python documentation: `typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal) +#[violation] +pub struct DuplicateLiteralMember { + duplicate_name: String, +} + +impl Violation for DuplicateLiteralMember { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + + #[derive_message_formats] + fn message(&self) -> String { + format!("Duplicate literal member `{}`", self.duplicate_name) + } +} + +/// PYI062 +pub(crate) fn duplicate_literal_member<'a>(checker: &mut Checker, expr: &'a Expr) { + let mut seen_nodes: HashSet, _> = FxHashSet::default(); + let mut diagnostics: Vec = Vec::new(); + + // Adds a member to `literal_exprs` if it is a `Literal` annotation + let mut check_for_duplicate_members = |expr: &'a Expr, _: &'a Expr| { + // If we've already seen this literal member, raise a violation. + if !seen_nodes.insert(expr.into()) { + let diagnostic = Diagnostic::new( + DuplicateLiteralMember { + duplicate_name: checker.generator().expr(expr), + }, + expr.range(), + ); + diagnostics.push(diagnostic); + } + }; + + // Traverse the literal, collect all diagnostic members + traverse_literal(&mut check_for_duplicate_members, checker.semantic(), expr); + checker.diagnostics.append(&mut diagnostics); +} diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs index 851b0660d113e..84c54f06376d2 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs @@ -6,6 +6,7 @@ pub(crate) use complex_assignment_in_stub::*; pub(crate) use complex_if_statement_in_stub::*; pub(crate) use custom_type_var_return_type::*; pub(crate) use docstring_in_stubs::*; +pub(crate) use duplicate_literal_member::*; pub(crate) use duplicate_union_member::*; pub(crate) use ellipsis_in_non_empty_class_body::*; pub(crate) use exit_annotations::*; @@ -44,6 +45,7 @@ mod complex_assignment_in_stub; mod complex_if_statement_in_stub; mod custom_type_var_return_type; mod docstring_in_stubs; +mod duplicate_literal_member; mod duplicate_union_member; mod ellipsis_in_non_empty_class_body; mod exit_annotations; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap new file mode 100644 index 0000000000000..7efbe2e7b6187 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap @@ -0,0 +1,42 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs +--- +PYI062.py:3:25: PYI062 Duplicate literal member `True` + | +1 | from typing import Literal +2 | +3 | x: Literal[True, False, True, False] # PYI062 twice here + | ^^^^ PYI062 +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 + | + +PYI062.py:3:31: PYI062 Duplicate literal member `False` + | +1 | from typing import Literal +2 | +3 | x: Literal[True, False, True, False] # PYI062 twice here + | ^^^^^ PYI062 +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 + | + +PYI062.py:5:45: PYI062 Duplicate literal member `1` + | +3 | x: Literal[True, False, True, False] # PYI062 twice here +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 + | ^ PYI062 +6 | +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + | + +PYI062.py:7:33: PYI062 Duplicate literal member `{1, 3, 5}` + | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 +6 | +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + | ^^^^^^^ PYI062 +8 | +9 | n: Literal["No", "duplicates", "here", 1, "1"] + | diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap new file mode 100644 index 0000000000000..ea88d28e8dca6 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap @@ -0,0 +1,42 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs +--- +PYI062.pyi:3:25: PYI062 Duplicate literal member `True` + | +1 | from typing import Literal +2 | +3 | x: Literal[True, False, True, False] # PY062 twice here + | ^^^^ PYI062 +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 + | + +PYI062.pyi:3:31: PYI062 Duplicate literal member `False` + | +1 | from typing import Literal +2 | +3 | x: Literal[True, False, True, False] # PY062 twice here + | ^^^^^ PYI062 +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 + | + +PYI062.pyi:5:45: PYI062 Duplicate literal member `1` + | +3 | x: Literal[True, False, True, False] # PY062 twice here +4 | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 + | ^ PYI062 +6 | +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + | + +PYI062.pyi:7:33: PYI062 Duplicate literal member `{1, 3, 5}` + | +5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 +6 | +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + | ^^^^^^^ PYI062 +8 | +9 | n: Literal["No", "duplicates", "here", 1, "1"] + | diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 88d0441e68667..d16e2e2931c21 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -418,6 +418,44 @@ where inner(func, semantic, expr, None); } +/// Traverse a "literal" type annotation, applying `func` to each literal member. +/// +/// The function is called with each expression in the literal (excluding declarations of nested +/// literals) and the parent expression. +pub fn traverse_literal<'a, F>(func: &mut F, semantic: &SemanticModel, expr: &'a Expr) +where + F: FnMut(&'a Expr, &'a Expr), +{ + fn inner<'a, F>( + func: &mut F, + semantic: &SemanticModel, + expr: &'a Expr, + parent: Option<&'a Expr>, + ) where + F: FnMut(&'a Expr, &'a Expr), + { + // Ex) Literal[x, y] + if let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = expr { + if semantic.match_typing_expr(value, "Literal") { + if let Expr::Tuple(ast::ExprTuple { elts, .. }) = slice.as_ref() { + // Traverse each element of the tuple within the literal recursively to handle cases + // such as `Literal[..., Literal[...]] + elts.iter() + .for_each(|elt| inner(func, semantic, elt, Some(expr))); + return; + } + } + } + + // Otherwise, call the function on expression, if it's not the top-level expression. + if let Some(parent) = parent { + func(expr, parent); + } + } + + inner(func, semantic, expr, None); +} + /// Abstraction for a type checker, conservatively checks for the intended type(s). pub trait TypeChecker { /// Check annotation expression to match the intended type(s). diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 8e0c0c1f47d29..ea6ca0e0e2e9a 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -1350,6 +1350,15 @@ impl<'a> SemanticModel<'a> { false } + /// Return `true` if the model is in a nested literal expression (e.g., the inner `Literal` in + /// `Literal[Literal[int, str], float]`). + pub fn in_nested_literal(&self) -> bool { + // Ex) `Literal[Literal[int, str], float]` + self.current_expression_grandparent() + .and_then(Expr::as_subscript_expr) + .is_some_and(|parent| self.match_typing_expr(&parent.value, "Literal")) + } + /// Returns `true` if `left` and `right` are in the same branches of an `if`, `match`, or /// `try` statement. /// From 85297ae610cae91686e8230444dcb31a69c15507 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 01:10:41 +0530 Subject: [PATCH 02/10] update schema --- ruff.schema.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruff.schema.json b/ruff.schema.json index 3c0072df3ede2..8c620799c77e6 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3573,6 +3573,8 @@ "PYI055", "PYI056", "PYI058", + "PYI06", + "PYI062", "Q", "Q0", "Q00", From a6e63367432644eb0da293df01617aa3b9d76bda Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 01:17:01 +0530 Subject: [PATCH 03/10] move rule to preview group --- crates/ruff_linter/src/codes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index f4e308c512a82..be1aa79edf2ef 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -808,7 +808,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Pyi, "055") => (RuleGroup::Stable, rules::flake8_pyi::rules::UnnecessaryTypeUnion), (Flake8Pyi, "056") => (RuleGroup::Stable, rules::flake8_pyi::rules::UnsupportedMethodCallOnAll), (Flake8Pyi, "058") => (RuleGroup::Stable, rules::flake8_pyi::rules::GeneratorReturnFromIterMethod), - (Flake8Pyi, "062") => (RuleGroup::Stable, rules::flake8_pyi::rules::DuplicateLiteralMember), + (Flake8Pyi, "062") => (RuleGroup::Preview, rules::flake8_pyi::rules::DuplicateLiteralMember), // flake8-pytest-style (Flake8PytestStyle, "001") => (RuleGroup::Stable, rules::flake8_pytest_style::rules::PytestFixtureIncorrectParenthesesStyle), From c8d315003471018ed0e021a0813da62087b3fc95 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 01:20:24 +0530 Subject: [PATCH 04/10] Add test for nested literals --- .../resources/test/fixtures/flake8_pyi/PYI062.py | 5 ++++- .../resources/test/fixtures/flake8_pyi/PYI062.pyi | 3 +++ ...ules__flake8_pyi__tests__PYI062_PYI062.py.snap | 15 ++++++++++++--- ...les__flake8_pyi__tests__PYI062_PYI062.pyi.snap | 11 ++++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py index 967f3cdb5ea08..dbb7b8ee70761 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py @@ -4,6 +4,9 @@ y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 -z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal + +# Ensure issue is only raised once, even on nested literals +MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 n: Literal["No", "duplicates", "here", 1, "1"] diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi index 28db68d785934..a67899c79bfc8 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi @@ -6,4 +6,7 @@ y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +# Ensure issue is only raised once, even on nested literals +MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 + n: Literal["No", "duplicates", "here", 1, "1"] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap index 7efbe2e7b6187..f7d26b52d4ac2 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap @@ -28,15 +28,24 @@ PYI062.py:5:45: PYI062 Duplicate literal member `1` 5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 | ^ PYI062 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal | PYI062.py:7:33: PYI062 Duplicate literal member `{1, 3, 5}` | 5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal | ^^^^^^^ PYI062 8 | -9 | n: Literal["No", "duplicates", "here", 1, "1"] +9 | # Ensure issue is only raised once, even on nested literals | + +PYI062.py:10:46: PYI062 Duplicate literal member `True` + | + 9 | # Ensure issue is only raised once, even on nested literals +10 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 + | ^^^^ PYI062 +11 | +12 | n: Literal["No", "duplicates", "here", 1, "1"] + | diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap index ea88d28e8dca6..febcc7aea6ff0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap @@ -38,5 +38,14 @@ PYI062.pyi:7:33: PYI062 Duplicate literal member `{1, 3, 5}` 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal | ^^^^^^^ PYI062 8 | -9 | n: Literal["No", "duplicates", "here", 1, "1"] +9 | # Ensure issue is only raised once, even on nested literals | + +PYI062.pyi:10:46: PYI062 Duplicate literal member `True` + | + 9 | # Ensure issue is only raised once, even on nested literals +10 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 + | ^^^^ PYI062 +11 | +12 | n: Literal["No", "duplicates", "here", 1, "1"] + | From ecff8c58c723a9879405ba240842c22807a7da8e Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 01:44:34 +0530 Subject: [PATCH 05/10] add a bunch more test cases --- .../test/fixtures/flake8_pyi/PYI062.py | 7 ++ .../test/fixtures/flake8_pyi/PYI062.pyi | 7 ++ ...__flake8_pyi__tests__PYI062_PYI062.py.snap | 99 +++++++++++++++++-- ..._flake8_pyi__tests__PYI062_PYI062.pyi.snap | 99 +++++++++++++++++-- .../src/analyze/typing.rs | 28 +++--- 5 files changed, 217 insertions(+), 23 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py index dbb7b8ee70761..e208a477887ff 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py @@ -6,6 +6,13 @@ z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal +Literal[1, Literal[1]] # once +Literal[1, 2, Literal[1, 2]] # twice +Literal[1, Literal[1], Literal[1]] # twice +Literal[1, Literal[2], Literal[2]] # once +Literal[1, Literal[2, Literal[1]]] # once +Literal[1, 1, 1] # twice + # Ensure issue is only raised once, even on nested literals MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi index a67899c79bfc8..d72a986248d1c 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi @@ -6,6 +6,13 @@ y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +Literal[1, Literal[1]] # once +Literal[1, 2, Literal[1, 2]] # twice +Literal[1, Literal[1], Literal[1]] # twice +Literal[1, Literal[2], Literal[2]] # once +Literal[1, Literal[2, Literal[1]]] # once +Literal[1, 1, 1] # twice + # Ensure issue is only raised once, even on nested literals MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap index f7d26b52d4ac2..905b18dc79b7c 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap @@ -38,14 +38,101 @@ PYI062.py:7:33: PYI062 Duplicate literal member `{1, 3, 5}` 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal | ^^^^^^^ PYI062 8 | -9 | # Ensure issue is only raised once, even on nested literals +9 | Literal[1, Literal[1]] # once | -PYI062.py:10:46: PYI062 Duplicate literal member `True` +PYI062.py:9:20: PYI062 Duplicate literal member `1` | - 9 | # Ensure issue is only raised once, even on nested literals -10 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 + 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal + 8 | + 9 | Literal[1, Literal[1]] # once + | ^ PYI062 +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | + +PYI062.py:10:23: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice + | ^ PYI062 +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | + +PYI062.py:10:26: PYI062 Duplicate literal member `2` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice + | ^ PYI062 +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | + +PYI062.py:11:20: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | ^ PYI062 +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | + +PYI062.py:11:32: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | ^ PYI062 +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | + +PYI062.py:12:32: PYI062 Duplicate literal member `2` + | +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | ^ PYI062 +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | + +PYI062.py:13:31: PYI062 Duplicate literal member `1` + | +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | ^ PYI062 +14 | Literal[1, 1, 1] # twice + | + +PYI062.py:14:12: PYI062 Duplicate literal member `1` + | +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | ^ PYI062 +15 | +16 | # Ensure issue is only raised once, even on nested literals + | + +PYI062.py:14:15: PYI062 Duplicate literal member `1` + | +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | ^ PYI062 +15 | +16 | # Ensure issue is only raised once, even on nested literals + | + +PYI062.py:17:46: PYI062 Duplicate literal member `True` + | +16 | # Ensure issue is only raised once, even on nested literals +17 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 | ^^^^ PYI062 -11 | -12 | n: Literal["No", "duplicates", "here", 1, "1"] +18 | +19 | n: Literal["No", "duplicates", "here", 1, "1"] | diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap index febcc7aea6ff0..29b4098b1810a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap @@ -38,14 +38,101 @@ PYI062.pyi:7:33: PYI062 Duplicate literal member `{1, 3, 5}` 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal | ^^^^^^^ PYI062 8 | -9 | # Ensure issue is only raised once, even on nested literals +9 | Literal[1, Literal[1]] # once | -PYI062.pyi:10:46: PYI062 Duplicate literal member `True` +PYI062.pyi:9:20: PYI062 Duplicate literal member `1` | - 9 | # Ensure issue is only raised once, even on nested literals -10 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 + 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + 8 | + 9 | Literal[1, Literal[1]] # once + | ^ PYI062 +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | + +PYI062.pyi:10:23: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice + | ^ PYI062 +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | + +PYI062.pyi:10:26: PYI062 Duplicate literal member `2` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice + | ^ PYI062 +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | + +PYI062.pyi:11:20: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | ^ PYI062 +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | + +PYI062.pyi:11:32: PYI062 Duplicate literal member `1` + | + 9 | Literal[1, Literal[1]] # once +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice + | ^ PYI062 +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | + +PYI062.pyi:12:32: PYI062 Duplicate literal member `2` + | +10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once + | ^ PYI062 +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | + +PYI062.pyi:13:31: PYI062 Duplicate literal member `1` + | +11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once + | ^ PYI062 +14 | Literal[1, 1, 1] # twice + | + +PYI062.pyi:14:12: PYI062 Duplicate literal member `1` + | +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | ^ PYI062 +15 | +16 | # Ensure issue is only raised once, even on nested literals + | + +PYI062.pyi:14:15: PYI062 Duplicate literal member `1` + | +12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, 1, 1] # twice + | ^ PYI062 +15 | +16 | # Ensure issue is only raised once, even on nested literals + | + +PYI062.pyi:17:46: PYI062 Duplicate literal member `True` + | +16 | # Ensure issue is only raised once, even on nested literals +17 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 | ^^^^ PYI062 -11 | -12 | n: Literal["No", "duplicates", "here", 1, "1"] +18 | +19 | n: Literal["No", "duplicates", "here", 1, "1"] | diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index d16e2e2931c21..85bc7ef267fbe 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -437,19 +437,25 @@ where // Ex) Literal[x, y] if let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = expr { if semantic.match_typing_expr(value, "Literal") { - if let Expr::Tuple(ast::ExprTuple { elts, .. }) = slice.as_ref() { - // Traverse each element of the tuple within the literal recursively to handle cases - // such as `Literal[..., Literal[...]] - elts.iter() - .for_each(|elt| inner(func, semantic, elt, Some(expr))); - return; + match slice.as_ref() { + Expr::Tuple(ast::ExprTuple { elts, .. }) => { + // Traverse each element of the tuple within the literal recursively to handle cases + // such as `Literal[..., Literal[...]] + elts.iter().for_each(|elt| { + inner(func, semantic, elt, Some(expr)); + }); + return; + } + other => { + inner(func, semantic, other, Some(expr)); + } } } - } - - // Otherwise, call the function on expression, if it's not the top-level expression. - if let Some(parent) = parent { - func(expr, parent); + } else { + // Otherwise, call the function on expression, if it's not the top-level expression. + if let Some(parent) = parent { + func(expr, parent); + } } } From 60bcb4e90ca3fe1eff0d65ce0660f061d303057c Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 4 May 2024 02:08:06 +0530 Subject: [PATCH 06/10] clippy --- crates/ruff_python_semantic/src/analyze/typing.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 85bc7ef267fbe..258fd3349f20a 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -441,10 +441,9 @@ where Expr::Tuple(ast::ExprTuple { elts, .. }) => { // Traverse each element of the tuple within the literal recursively to handle cases // such as `Literal[..., Literal[...]] - elts.iter().for_each(|elt| { + for elt in elts { inner(func, semantic, elt, Some(expr)); - }); - return; + } } other => { inner(func, semantic, other, Some(expr)); From 40c75fb532288a1c2792cfeb2e8519613f5d65cd Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 7 May 2024 21:17:23 +0530 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Alex Waygood --- .../flake8_pyi/rules/duplicate_literal_member.rs | 11 +++++------ crates/ruff_python_semantic/src/analyze/typing.rs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs index b68f441f54a69..4c3a8001dc6d6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -12,19 +12,19 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for duplicate literal members. +/// Checks for duplicate members in a `typing.Literal[]` slice. /// /// ## Why is this bad? /// Duplicate literal members are redundant and should be removed. /// /// ## Example /// ```python -/// foo: Literal[True, False, True] +/// foo: Literal["a", "b", "a"] /// ``` /// /// Use instead: /// ```python -/// foo: Literal[True, False] +/// foo: Literal["a", "b"] /// ``` /// /// ## References @@ -52,13 +52,12 @@ pub(crate) fn duplicate_literal_member<'a>(checker: &mut Checker, expr: &'a Expr let mut check_for_duplicate_members = |expr: &'a Expr, _: &'a Expr| { // If we've already seen this literal member, raise a violation. if !seen_nodes.insert(expr.into()) { - let diagnostic = Diagnostic::new( + diagnostics.push(Diagnostic::new( DuplicateLiteralMember { duplicate_name: checker.generator().expr(expr), }, expr.range(), - ); - diagnostics.push(diagnostic); + )); } }; diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 258fd3349f20a..08875307d0c98 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -437,7 +437,7 @@ where // Ex) Literal[x, y] if let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = expr { if semantic.match_typing_expr(value, "Literal") { - match slice.as_ref() { + match &**slice { Expr::Tuple(ast::ExprTuple { elts, .. }) => { // Traverse each element of the tuple within the literal recursively to handle cases // such as `Literal[..., Literal[...]] From 784eb52392000deea11b8108f5de4829c9ee1147 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 7 May 2024 23:12:08 +0530 Subject: [PATCH 08/10] update examples --- .../test/fixtures/flake8_pyi/PYI062.py | 6 +- .../test/fixtures/flake8_pyi/PYI062.pyi | 6 +- ...__flake8_pyi__tests__PYI062_PYI062.py.snap | 168 +++++++++--------- ..._flake8_pyi__tests__PYI062_PYI062.pyi.snap | 168 +++++++++--------- 4 files changed, 176 insertions(+), 172 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py index e208a477887ff..9e3b46c1f80c0 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.py @@ -1,4 +1,6 @@ from typing import Literal +import typing as t +import typing_extensions x: Literal[True, False, True, False] # PYI062 twice here @@ -10,8 +12,8 @@ Literal[1, 2, Literal[1, 2]] # twice Literal[1, Literal[1], Literal[1]] # twice Literal[1, Literal[2], Literal[2]] # once -Literal[1, Literal[2, Literal[1]]] # once -Literal[1, 1, 1] # twice +t.Literal[1, t.Literal[2, t.Literal[1]]] # once +typing_extensions.Literal[1, 1, 1] # twice # Ensure issue is only raised once, even on nested literals MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi index d72a986248d1c..38d04bcd9df68 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI062.pyi @@ -1,4 +1,6 @@ from typing import Literal +import typing as t +import typing_extensions x: Literal[True, False, True, False] # PY062 twice here @@ -10,8 +12,8 @@ Literal[1, Literal[1]] # once Literal[1, 2, Literal[1, 2]] # twice Literal[1, Literal[1], Literal[1]] # twice Literal[1, Literal[2], Literal[2]] # once -Literal[1, Literal[2, Literal[1]]] # once -Literal[1, 1, 1] # twice +t.Literal[1, t.Literal[2, t.Literal[1]]] # once +typing_extensions.Literal[1, 1, 1] # twice # Ensure issue is only raised once, even on nested literals MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap index 905b18dc79b7c..2ed8215957160 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.py.snap @@ -1,138 +1,138 @@ --- source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs --- -PYI062.py:3:25: PYI062 Duplicate literal member `True` +PYI062.py:5:25: PYI062 Duplicate literal member `True` | -1 | from typing import Literal -2 | -3 | x: Literal[True, False, True, False] # PYI062 twice here - | ^^^^ PYI062 -4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 - | - -PYI062.py:3:31: PYI062 Duplicate literal member `False` - | -1 | from typing import Literal -2 | -3 | x: Literal[True, False, True, False] # PYI062 twice here - | ^^^^^ PYI062 +3 | import typing_extensions 4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 +5 | x: Literal[True, False, True, False] # PYI062 twice here + | ^^^^ PYI062 +6 | +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 | -PYI062.py:5:45: PYI062 Duplicate literal member `1` +PYI062.py:5:31: PYI062 Duplicate literal member `False` | -3 | x: Literal[True, False, True, False] # PYI062 twice here +3 | import typing_extensions 4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 - | ^ PYI062 +5 | x: Literal[True, False, True, False] # PYI062 twice here + | ^^^^^ PYI062 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 | -PYI062.py:7:33: PYI062 Duplicate literal member `{1, 3, 5}` +PYI062.py:7:45: PYI062 Duplicate literal member `1` | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 +5 | x: Literal[True, False, True, False] # PYI062 twice here 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal - | ^^^^^^^ PYI062 +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 + | ^ PYI062 8 | -9 | Literal[1, Literal[1]] # once +9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal | -PYI062.py:9:20: PYI062 Duplicate literal member `1` +PYI062.py:9:33: PYI062 Duplicate literal member `{1, 3, 5}` | - 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal + 7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PYI062 on the last 1 8 | - 9 | Literal[1, Literal[1]] # once + 9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal + | ^^^^^^^ PYI062 +10 | +11 | Literal[1, Literal[1]] # once + | + +PYI062.py:11:20: PYI062 Duplicate literal member `1` + | + 9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PYI062 on the set literal +10 | +11 | Literal[1, Literal[1]] # once | ^ PYI062 -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | -PYI062.py:10:23: PYI062 Duplicate literal member `1` +PYI062.py:12:23: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice | ^ PYI062 -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | -PYI062.py:10:26: PYI062 Duplicate literal member `2` +PYI062.py:12:26: PYI062 Duplicate literal member `2` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice | ^ PYI062 -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | -PYI062.py:11:20: PYI062 Duplicate literal member `1` +PYI062.py:13:20: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | ^ PYI062 -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once | -PYI062.py:11:32: PYI062 Duplicate literal member `1` +PYI062.py:13:32: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | ^ PYI062 -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once | -PYI062.py:12:32: PYI062 Duplicate literal member `2` +PYI062.py:14:32: PYI062 Duplicate literal member `2` | -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | ^ PYI062 -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice | -PYI062.py:13:31: PYI062 Duplicate literal member `1` +PYI062.py:15:37: PYI062 Duplicate literal member `1` | -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once - | ^ PYI062 -14 | Literal[1, 1, 1] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once + | ^ PYI062 +16 | typing_extensions.Literal[1, 1, 1] # twice | -PYI062.py:14:12: PYI062 Duplicate literal member `1` +PYI062.py:16:30: PYI062 Duplicate literal member `1` | -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice - | ^ PYI062 -15 | -16 | # Ensure issue is only raised once, even on nested literals +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice + | ^ PYI062 +17 | +18 | # Ensure issue is only raised once, even on nested literals | -PYI062.py:14:15: PYI062 Duplicate literal member `1` +PYI062.py:16:33: PYI062 Duplicate literal member `1` | -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice - | ^ PYI062 -15 | -16 | # Ensure issue is only raised once, even on nested literals +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice + | ^ PYI062 +17 | +18 | # Ensure issue is only raised once, even on nested literals | -PYI062.py:17:46: PYI062 Duplicate literal member `True` +PYI062.py:19:46: PYI062 Duplicate literal member `True` | -16 | # Ensure issue is only raised once, even on nested literals -17 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 +18 | # Ensure issue is only raised once, even on nested literals +19 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 | ^^^^ PYI062 -18 | -19 | n: Literal["No", "duplicates", "here", 1, "1"] +20 | +21 | n: Literal["No", "duplicates", "here", 1, "1"] | diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap index 29b4098b1810a..069024753f74b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI062_PYI062.pyi.snap @@ -1,138 +1,138 @@ --- source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs --- -PYI062.pyi:3:25: PYI062 Duplicate literal member `True` +PYI062.pyi:5:25: PYI062 Duplicate literal member `True` | -1 | from typing import Literal -2 | -3 | x: Literal[True, False, True, False] # PY062 twice here - | ^^^^ PYI062 -4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 - | - -PYI062.pyi:3:31: PYI062 Duplicate literal member `False` - | -1 | from typing import Literal -2 | -3 | x: Literal[True, False, True, False] # PY062 twice here - | ^^^^^ PYI062 +3 | import typing_extensions 4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 +5 | x: Literal[True, False, True, False] # PY062 twice here + | ^^^^ PYI062 +6 | +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 | -PYI062.pyi:5:45: PYI062 Duplicate literal member `1` +PYI062.pyi:5:31: PYI062 Duplicate literal member `False` | -3 | x: Literal[True, False, True, False] # PY062 twice here +3 | import typing_extensions 4 | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 - | ^ PYI062 +5 | x: Literal[True, False, True, False] # PY062 twice here + | ^^^^^ PYI062 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 | -PYI062.pyi:7:33: PYI062 Duplicate literal member `{1, 3, 5}` +PYI062.pyi:7:45: PYI062 Duplicate literal member `1` | -5 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 +5 | x: Literal[True, False, True, False] # PY062 twice here 6 | -7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal - | ^^^^^^^ PYI062 +7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 + | ^ PYI062 8 | -9 | Literal[1, Literal[1]] # once +9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal | -PYI062.pyi:9:20: PYI062 Duplicate literal member `1` +PYI062.pyi:9:33: PYI062 Duplicate literal member `{1, 3, 5}` | - 7 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + 7 | y: Literal[1, print("hello"), 3, Literal[4, 1]] # PY062 on the last 1 8 | - 9 | Literal[1, Literal[1]] # once + 9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal + | ^^^^^^^ PYI062 +10 | +11 | Literal[1, Literal[1]] # once + | + +PYI062.pyi:11:20: PYI062 Duplicate literal member `1` + | + 9 | z: Literal[{1, 3, 5}, "foobar", {1,3,5}] # PY062 on the set literal +10 | +11 | Literal[1, Literal[1]] # once | ^ PYI062 -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | -PYI062.pyi:10:23: PYI062 Duplicate literal member `1` +PYI062.pyi:12:23: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice | ^ PYI062 -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | -PYI062.pyi:10:26: PYI062 Duplicate literal member `2` +PYI062.pyi:12:26: PYI062 Duplicate literal member `2` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice | ^ PYI062 -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | -PYI062.pyi:11:20: PYI062 Duplicate literal member `1` +PYI062.pyi:13:20: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | ^ PYI062 -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once | -PYI062.pyi:11:32: PYI062 Duplicate literal member `1` +PYI062.pyi:13:32: PYI062 Duplicate literal member `1` | - 9 | Literal[1, Literal[1]] # once -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice +11 | Literal[1, Literal[1]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice | ^ PYI062 -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once | -PYI062.pyi:12:32: PYI062 Duplicate literal member `2` +PYI062.pyi:14:32: PYI062 Duplicate literal member `2` | -10 | Literal[1, 2, Literal[1, 2]] # twice -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once +12 | Literal[1, 2, Literal[1, 2]] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once | ^ PYI062 -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice | -PYI062.pyi:13:31: PYI062 Duplicate literal member `1` +PYI062.pyi:15:37: PYI062 Duplicate literal member `1` | -11 | Literal[1, Literal[1], Literal[1]] # twice -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once - | ^ PYI062 -14 | Literal[1, 1, 1] # twice +13 | Literal[1, Literal[1], Literal[1]] # twice +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once + | ^ PYI062 +16 | typing_extensions.Literal[1, 1, 1] # twice | -PYI062.pyi:14:12: PYI062 Duplicate literal member `1` +PYI062.pyi:16:30: PYI062 Duplicate literal member `1` | -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice - | ^ PYI062 -15 | -16 | # Ensure issue is only raised once, even on nested literals +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice + | ^ PYI062 +17 | +18 | # Ensure issue is only raised once, even on nested literals | -PYI062.pyi:14:15: PYI062 Duplicate literal member `1` +PYI062.pyi:16:33: PYI062 Duplicate literal member `1` | -12 | Literal[1, Literal[2], Literal[2]] # once -13 | Literal[1, Literal[2, Literal[1]]] # once -14 | Literal[1, 1, 1] # twice - | ^ PYI062 -15 | -16 | # Ensure issue is only raised once, even on nested literals +14 | Literal[1, Literal[2], Literal[2]] # once +15 | t.Literal[1, t.Literal[2, t.Literal[1]]] # once +16 | typing_extensions.Literal[1, 1, 1] # twice + | ^ PYI062 +17 | +18 | # Ensure issue is only raised once, even on nested literals | -PYI062.pyi:17:46: PYI062 Duplicate literal member `True` +PYI062.pyi:19:46: PYI062 Duplicate literal member `True` | -16 | # Ensure issue is only raised once, even on nested literals -17 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 +18 | # Ensure issue is only raised once, even on nested literals +19 | MyType = Literal["foo", Literal[True, False, True], "bar"] # PYI062 | ^^^^ PYI062 -18 | -19 | n: Literal["No", "duplicates", "here", 1, "1"] +20 | +21 | n: Literal["No", "duplicates", "here", 1, "1"] | From f2797de8bac681b0825314d87e03d149f14491a0 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 7 May 2024 23:18:35 +0530 Subject: [PATCH 09/10] remove visit in binop --- crates/ruff_linter/src/checkers/ast/analyze/expression.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 2c062bef928bc..b526dd37777da 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1200,14 +1200,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { ruff::rules::never_union(checker, expr); } - // Avoid duplicate checks if the parent is a literal, since this rule already - // traverses nested literals. - if checker.enabled(Rule::DuplicateLiteralMember) { - if !checker.semantic.in_nested_literal() { - flake8_pyi::rules::duplicate_literal_member(checker, expr); - } - } - // Avoid duplicate checks if the parent is a union, since these rules already // traverse nested unions. if !checker.semantic.in_nested_union() { From 8ccf5698eb301468eb75373f263d4fec431f87f1 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 7 May 2024 23:23:22 +0530 Subject: [PATCH 10/10] undo unnecessary schema changes --- ruff.schema.json | 855 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 682 insertions(+), 173 deletions(-) diff --git a/ruff.schema.json b/ruff.schema.json index e9d9212a7f78a..33cc16342c78f 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -6,7 +6,10 @@ "allowed-confusables": { "description": "A list of allowed \"confusable\" Unicode characters to ignore when enforcing `RUF001`, `RUF002`, and `RUF003`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string", "maxLength": 1, @@ -15,23 +18,35 @@ }, "builtins": { "description": "A list of builtins to treat as defined references, in addition to the system builtins.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "cache-dir": { "description": "A path to the cache directory.\n\nBy default, Ruff stores cache results in a `.ruff_cache` directory in the current project root.\n\nHowever, Ruff will also respect the `RUFF_CACHE_DIR` environment variable, which takes precedence over that default.\n\nThis setting will override even the `RUFF_CACHE_DIR` environment variable, if set.", - "type": ["string", "null"] + "type": [ + "string", + "null" + ] }, "dummy-variable-rgx": { "description": "A regular expression used to identify \"dummy\" variables, or those which should be ignored when enforcing (e.g.) unused-variable rules. The default expression matches `_`, `__`, and `_var`, but not `_var_`.", "deprecated": true, - "type": ["string", "null"] + "type": [ + "string", + "null" + ] }, "exclude": { "description": "A list of file patterns to exclude from formatting and linting.\n\nExclusions are based on globs, and can be either:\n\n- Single-path patterns, like `.mypy_cache` (to exclude any directory named `.mypy_cache` in the tree), `foo.py` (to exclude any file named `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ). - Relative patterns, like `directory/foo.py` (to exclude that specific file) or `directory/*.py` (to exclude any Python files in `directory`). Note that these paths are relative to the project root (e.g., the directory containing your `pyproject.toml`).\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).\n\nNote that you'll typically want to use [`extend-exclude`](#extend-exclude) to modify the excluded paths.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -39,15 +54,24 @@ "explicit-preview-rules": { "description": "Whether to require exact codes to select preview rules. When enabled, preview rules will not be selected by prefixes — the full code of each preview rule will be required to enable the rule.", "deprecated": true, - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "extend": { "description": "A path to a local `pyproject.toml` file to merge into this configuration. User home directory and environment variables will be expanded.\n\nTo resolve the current `pyproject.toml` file, Ruff will first resolve this base configuration file, then merge in any properties defined in the current configuration file.", - "type": ["string", "null"] + "type": [ + "string", + "null" + ] }, "extend-exclude": { "description": "A list of file patterns to omit from formatting and linting, in addition to those specified by `exclude`.\n\nExclusions are based on globs, and can be either:\n\n- Single-path patterns, like `.mypy_cache` (to exclude any directory named `.mypy_cache` in the tree), `foo.py` (to exclude any file named `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ). - Relative patterns, like `directory/foo.py` (to exclude that specific file) or `directory/*.py` (to exclude any Python files in `directory`). Note that these paths are relative to the project root (e.g., the directory containing your `pyproject.toml`).\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -55,7 +79,10 @@ "extend-fixable": { "description": "A list of rule codes or prefixes to consider fixable, in addition to those specified by `fixable`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -63,14 +90,20 @@ "extend-ignore": { "description": "A list of rule codes or prefixes to ignore, in addition to those specified by `ignore`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "extend-include": { "description": "A list of file patterns to include when linting, in addition to those specified by `include`.\n\nInclusion are based on globs, and should be single-path patterns, like `*.pyw`, to include any file with the `.pyw` extension.\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -78,7 +111,10 @@ "extend-per-file-ignores": { "description": "A list of mappings from file pattern to rule codes or prefixes to exclude, in addition to any rules excluded by `per-file-ignores`.", "deprecated": true, - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "array", "items": { @@ -89,7 +125,10 @@ "extend-safe-fixes": { "description": "A list of rule codes or prefixes for which unsafe fixes should be considered safe.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -97,7 +136,10 @@ "extend-select": { "description": "A list of rule codes or prefixes to enable, in addition to those specified by `select`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -105,7 +147,10 @@ "extend-unfixable": { "description": "A list of rule codes or prefixes to consider non-auto-fixable, in addition to those specified by `unfixable`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -113,7 +158,10 @@ "extend-unsafe-fixes": { "description": "A list of rule codes or prefixes for which safe fixes should be considered unsafe.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -121,23 +169,35 @@ "external": { "description": "A list of rule codes or prefixes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "fix": { "description": "Enable fix behavior by-default when running `ruff` (overridden by the `--fix` and `--no-fix` command-line flags). Only includes automatic fixes unless `--unsafe-fixes` is provided.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "fix-only": { "description": "Like `fix`, but disables reporting on leftover violation. Implies `fix`.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "fixable": { "description": "A list of rule codes or prefixes to consider fixable. By default, all rules are considered fixable.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -348,7 +408,10 @@ }, "force-exclude": { "description": "Whether to enforce `exclude` and `extend-exclude` patterns, even for paths that are passed to Ruff explicitly. Typically, Ruff will lint any paths passed in directly, even if they would typically be excluded. Setting `force-exclude = true` will cause Ruff to respect these exclusions unequivocally.\n\nThis is useful for [`pre-commit`](https://pre-commit.com/), which explicitly passes all changed files to the [`ruff-pre-commit`](https://github.com/astral-sh/ruff-pre-commit) plugin, regardless of whether they're marked as excluded by Ruff's own settings.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "format": { "description": "Options to configure code formatting.", @@ -364,7 +427,10 @@ "ignore": { "description": "A list of rule codes or prefixes to ignore. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -372,11 +438,17 @@ "ignore-init-module-imports": { "description": "Avoid automatically removing unused imports in `__init__.py` files. Such imports will still be flagged, but with a dedicated message suggesting that the import is either added to the module's `__all__` symbol, or re-exported with a redundant alias (e.g., `import os as os`).\n\nThis option is enabled by default, but you can opt-in to removal of imports via an unsafe fix.", "deprecated": true, - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "include": { "description": "A list of file patterns to include when linting.\n\nInclusion are based on globs, and should be single-path patterns, like `*.pyw`, to include any file with the `.pyw` extension. `pyproject.toml` is included here not for configuration but because we lint whether e.g. the `[project]` matches the schema.\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -428,7 +500,10 @@ "logger-objects": { "description": "A list of objects that should be treated equivalently to a `logging.Logger` object.\n\nThis is useful for ensuring proper diagnostics (e.g., to identify `logging` deprecations and other best-practices) for projects that re-export a `logging.Logger` object from a common module.\n\nFor example, if you have a module `logging_setup.py` with the following contents: ```python import logging\n\nlogger = logging.getLogger(__name__) ```\n\nAdding `\"logging_setup.logger\"` to `logger-objects` will ensure that `logging_setup.logger` is treated as a `logging.Logger` object when imported from other modules (e.g., `from logging_setup import logger`).", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -447,7 +522,10 @@ }, "namespace-packages": { "description": "Mark the specified directories as namespace packages. For the purpose of module resolution, Ruff will treat those directories and all their subdirectories as if they contained an `__init__.py` file.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -478,7 +556,10 @@ "per-file-ignores": { "description": "A list of mappings from file pattern to rule codes or prefixes to exclude, when considering any matching files. An initial '!' negates the file pattern.", "deprecated": true, - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "array", "items": { @@ -488,7 +569,10 @@ }, "preview": { "description": "Whether to enable preview mode. When preview mode is enabled, Ruff will use unstable rules, fixes, and formatting.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "pycodestyle": { "description": "Options for the `pycodestyle` plugin.", @@ -563,28 +647,43 @@ }, "respect-gitignore": { "description": "Whether to automatically exclude files that are ignored by `.ignore`, `.gitignore`, `.git/info/exclude`, and global `gitignore` files. Enabled by default.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "select": { "description": "A list of rule codes or prefixes to enable. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "show-fixes": { "description": "Whether to show an enumeration of all fixed lint violations (overridden by the `--show-fixes` command-line flag).", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "show-source": { "description": "Whether to show source code snippets when reporting lint violations (overridden by the `--show-source` command-line flag).", "deprecated": true, - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "src": { "description": "The directories to consider when resolving first- vs. third-party imports.\n\nAs an example: given a Python package structure like:\n\n```text my_project ├── pyproject.toml └── src └── my_package ├── __init__.py ├── foo.py └── bar.py ```\n\nThe `./src` directory should be included in the `src` option (e.g., `src = [\"src\"]`), such that when resolving imports, `my_package.foo` is considered a first-party import.\n\nWhen omitted, the `src` directory will typically default to the directory containing the nearest `pyproject.toml`, `ruff.toml`, or `.ruff.toml` file (the \"project root\"), unless a configuration file is explicitly provided (e.g., via the `--config` command-line flag).\n\nThis field supports globs. For example, if you have a series of Python packages in a `python_modules` directory, `src = [\"python_modules/*\"]` would expand to incorporate all of the packages in that directory. User home directory and environment variables will also be expanded.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -615,7 +714,10 @@ "task-tags": { "description": "A list of task tags to recognize (e.g., \"TODO\", \"FIXME\", \"XXX\").\n\nComments starting with these tags will be ignored by commented-out code detection (`ERA`), and skipped by line-length rules (`E501`) if `ignore-overlong-task-comments` is set to `true`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -623,7 +725,10 @@ "typing-modules": { "description": "A list of modules whose exports should be treated equivalently to members of the `typing` module.\n\nThis is useful for ensuring proper type annotation inference for projects that re-export `typing` and `typing_extensions` members from a compatibility module. If omitted, any members imported from modules apart from `typing` and `typing_extensions` will be treated as ordinary Python objects.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -631,21 +736,29 @@ "unfixable": { "description": "A list of rule codes or prefixes to consider non-fixable.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "unsafe-fixes": { "description": "Enable application of unsafe fixes. If excluded, a hint will be displayed when unsafe fixes are available. If set to false, the hint will be hidden.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false, "definitions": { "ApiBan": { "type": "object", - "required": ["msg"], + "required": [ + "msg" + ], "properties": { "msg": { "description": "The message to display when the API is used.", @@ -662,24 +775,36 @@ }, "ConstantType": { "type": "string", - "enum": ["bytes", "complex", "float", "int", "str"] + "enum": [ + "bytes", + "complex", + "float", + "int", + "str" + ] }, "Convention": { "oneOf": [ { "description": "Use Google-style docstrings.", "type": "string", - "enum": ["google"] + "enum": [ + "google" + ] }, { "description": "Use NumPy-style docstrings.", "type": "string", - "enum": ["numpy"] + "enum": [ + "numpy" + ] }, { "description": "Use PEP257-style docstrings.", "type": "string", - "enum": ["pep257"] + "enum": [ + "pep257" + ] } ] }, @@ -712,23 +837,38 @@ "properties": { "allow-star-arg-any": { "description": "Whether to suppress `ANN401` for dynamically typed `*args` and `**kwargs` arguments.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "ignore-fully-untyped": { "description": "Whether to suppress `ANN*` rules for any declaration that hasn't been typed at all. This makes it easier to gradually add types to a codebase.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "mypy-init-return": { "description": "Whether to allow the omission of a return type hint for `__init__` if at least one argument is annotated.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "suppress-dummy-args": { "description": "Whether to suppress `ANN000`-level violations for arguments matching the \"dummy\" variable regex (like `_`).", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "suppress-none-returning": { "description": "Whether to suppress `ANN200`-level violations for functions that meet either of the following criteria:\n\n- Contain no `return` statement. - Explicit `return` statement(s) all return `None` (explicitly or implicitly).", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -738,18 +878,27 @@ "properties": { "check-typed-exception": { "description": "Whether to disallow `try`-`except`-`pass` (`S110`) for specific exception types. By default, `try`-`except`-`pass` is only disallowed for `Exception` and `BaseException`.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "hardcoded-tmp-directory": { "description": "A list of directories to consider temporary.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "hardcoded-tmp-directory-extend": { "description": "A list of directories to consider temporary, in addition to those specified by `hardcoded-tmp-directory`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -762,7 +911,10 @@ "properties": { "extend-allowed-calls": { "description": "Additional callable functions with which to allow boolean traps.\n\nExpects to receive a list of fully-qualified names (e.g., `pydantic.Field`, rather than `Field`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -775,7 +927,10 @@ "properties": { "extend-immutable-calls": { "description": "Additional callable functions to consider \"immutable\" when evaluating, e.g., the `function-call-in-default-argument` rule (`B008`) or `function-call-in-dataclass-defaults` rule (`RUF009`).\n\nExpects to receive a list of fully-qualified names (e.g., `fastapi.Query`, rather than `Query`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -788,7 +943,10 @@ "properties": { "builtins-ignorelist": { "description": "Ignore list of builtins.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -801,7 +959,10 @@ "properties": { "allow-dict-calls-with-keyword-arguments": { "description": "Allow `dict` calls that make use of keyword arguments (e.g., `dict(a=1, b=2)`).", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -811,17 +972,26 @@ "properties": { "author": { "description": "Author to enforce within the copyright notice. If provided, the author must be present immediately following the copyright notice.", - "type": ["string", "null"] + "type": [ + "string", + "null" + ] }, "min-file-size": { "description": "A minimum file size (in bytes) required for a copyright notice to be enforced. By default, all files are validated.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "notice-rgx": { "description": "The regular expression used to match the copyright notice, compiled with the [`regex`](https://docs.rs/regex/latest/regex/) crate. Defaults to `(?i)Copyright\\s+((?:\\(C\\)|©)\\s+)?\\d{4}((-|,\\s)\\d{4})*`, which matches the following:\n\n- `Copyright 2023` - `Copyright (C) 2023` - `Copyright 2021-2023` - `Copyright (C) 2021-2023` - `Copyright (C) 2021, 2023`", - "type": ["string", "null"] + "type": [ + "string", + "null" + ] } }, "additionalProperties": false @@ -831,7 +1001,10 @@ "properties": { "max-string-length": { "description": "Maximum string length for string literals in exception messages.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 } @@ -843,14 +1016,20 @@ "properties": { "extend-function-names": { "description": "Additional function names to consider as internationalization calls, in addition to those included in `function-names`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "function-names": { "description": "The function names to consider as internationalization calls.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -863,7 +1042,10 @@ "properties": { "allow-multiline": { "description": "Whether to allow implicit string concatenations for multiline strings. By default, implicit concatenations of multiline strings are allowed (but continuation lines, delimited with a backslash, are prohibited).\n\nNote that setting `allow-multiline = false` should typically be coupled with disabling `explicit-string-concatenation` (`ISC003`). Otherwise, both explicit and implicit multiline string concatenations will be seen as violations.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -873,21 +1055,30 @@ "properties": { "aliases": { "description": "The conventional aliases for imports. These aliases can be extended by the `extend-aliases` option.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "string" } }, "banned-aliases": { "description": "A mapping from module to its banned import aliases.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "$ref": "#/definitions/BannedAliases" } }, "banned-from": { "description": "A list of modules that should not be imported from using the `from ... import ...` syntax.\n\nFor example, given `banned-from = [\"pandas\"]`, `from pandas import DataFrame` would be disallowed, while `import pandas` would be allowed.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" }, @@ -895,7 +1086,10 @@ }, "extend-aliases": { "description": "A mapping from module to conventional import alias. These aliases will be added to the `aliases` mapping.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "string" } @@ -908,11 +1102,17 @@ "properties": { "fixture-parentheses": { "description": "Boolean flag specifying whether `@pytest.fixture()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.fixture()` is valid and `@pytest.fixture` is invalid. If set to `false`, `@pytest.fixture` is valid and `@pytest.fixture()` is invalid.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "mark-parentheses": { "description": "Boolean flag specifying whether `@pytest.mark.foo()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is invalid. If set to `false`, `@pytest.fixture` is valid and `@pytest.mark.foo()` is invalid.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "parametrize-names-type": { "description": "Expected type for multiple argument names in `@pytest.mark.parametrize`. The following values are supported:\n\n- `csv` — a comma-separated list, e.g. `@pytest.mark.parametrize('name1,name2', ...)` - `tuple` (default) — e.g. `@pytest.mark.parametrize(('name1', 'name2'), ...)` - `list` — e.g. `@pytest.mark.parametrize(['name1', 'name2'], ...)`", @@ -949,14 +1149,20 @@ }, "raises-extend-require-match-for": { "description": "List of additional exception names that require a match= parameter in a `pytest.raises()` call. This extends the default list of exceptions that require a match= parameter. This option is useful if you want to extend the default list of exceptions that require a match= parameter without having to specify the entire list. Note that this option does not remove any exceptions from the default list.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "raises-require-match-for": { "description": "List of exception names that require a match= parameter in a `pytest.raises()` call.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -969,7 +1175,10 @@ "properties": { "avoid-escape": { "description": "Whether to avoid using single quotes if a string contains single quotes, or vice-versa with double quotes, as per [PEP 8](https://peps.python.org/pep-0008/#string-quotes). This minimizes the need to escape quotation marks within strings.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "docstring-quotes": { "description": "Quote style to prefer for docstrings (either \"single\" or \"double\").\n\nWhen using the formatter, only \"double\" is compatible, as the formatter enforces double quotes for docstrings strings.", @@ -1012,14 +1221,20 @@ "properties": { "extend-ignore-names": { "description": "Additional names to ignore when considering `flake8-self` violations, in addition to those included in `ignore-names`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "ignore-names": { "description": "A list of names to ignore when considering `flake8-self` violations.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1043,14 +1258,20 @@ }, "banned-api": { "description": "Specific modules or module members that may not be imported or accessed. Note that this rule is only meant to flag accidental uses, and can be circumvented via `eval` or `importlib`.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "$ref": "#/definitions/ApiBan" } }, "banned-module-level-imports": { "description": "List of specific modules that may not be imported at module level, and should instead be imported lazily (e.g., within a function definition, or an `if TYPE_CHECKING:` block, or some other nested context).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1063,32 +1284,47 @@ "properties": { "exempt-modules": { "description": "Exempt certain modules from needing to be moved into type-checking blocks.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "quote-annotations": { "description": "Whether to add quotes around type annotations, if doing so would allow the corresponding import to be moved into a type-checking block.\n\nFor example, in the following, Python requires that `Sequence` be available at runtime, despite the fact that it's only used in a type annotation:\n\n```python from collections.abc import Sequence\n\ndef func(value: Sequence[int]) -> None: ... ```\n\nIn other words, moving `from collections.abc import Sequence` into an `if TYPE_CHECKING:` block above would cause a runtime error, as the type would no longer be available at runtime.\n\nBy default, Ruff will respect such runtime semantics and avoid moving the import to prevent such runtime errors.\n\nSetting `quote-annotations` to `true` will instruct Ruff to add quotes around the annotation (e.g., `\"Sequence[int]\"`), which in turn enables Ruff to move the import into an `if TYPE_CHECKING:` block, like so:\n\n```python from typing import TYPE_CHECKING\n\nif TYPE_CHECKING: from collections.abc import Sequence\n\ndef func(value: \"Sequence[int]\") -> None: ... ```\n\nNote that this setting has no effect when `from __future__ import annotations` is present, as `__future__` annotations are always treated equivalently to quoted annotations.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "runtime-evaluated-base-classes": { "description": "Exempt classes that list any of the enumerated classes as a base class from needing to be moved into type-checking blocks.\n\nCommon examples include Pydantic's `pydantic.BaseModel` and SQLAlchemy's `sqlalchemy.orm.DeclarativeBase`, but can also support user-defined classes that inherit from those base classes. For example, if you define a common `DeclarativeBase` subclass that's used throughout your project (e.g., `class Base(DeclarativeBase) ...` in `base.py`), you can add it to this list (`runtime-evaluated-base-classes = [\"base.Base\"]`) to exempt models from being moved into type-checking blocks.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "runtime-evaluated-decorators": { "description": "Exempt classes and functions decorated with any of the enumerated decorators from being moved into type-checking blocks.\n\nCommon examples include Pydantic's `@pydantic.validate_call` decorator (for functions) and attrs' `@attrs.define` decorator (for classes).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "strict": { "description": "Enforce TC001, TC002, and TC003 rules even when valid runtime imports are present for the same module.\n\nSee flake8-type-checking's [strict](https://github.com/snok/flake8-type-checking#strict) option.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -1098,7 +1334,10 @@ "properties": { "ignore-variadic-names": { "description": "Whether to allow unused variadic arguments, like `*args` and `**kwargs`.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -1109,7 +1348,10 @@ "properties": { "docstring-code-format": { "description": "Whether to format code snippets in docstrings.\n\nWhen this is enabled, Python code examples within docstrings are automatically reformatted.\n\nFor example, when this is enabled, the following code:\n\n```python def f(x): \"\"\" Something about `f`. And an example in doctest format:\n\n>>> f( x )\n\nMarkdown is also supported:\n\n```py f( x ) ```\n\nAs are reStructuredText literal blocks::\n\nf( x )\n\nAnd reStructuredText code blocks:\n\n.. code-block:: python\n\nf( x ) \"\"\" pass ```\n\n... will be reformatted (assuming the rest of the options are set to their defaults) as:\n\n```python def f(x): \"\"\" Something about `f`. And an example in doctest format:\n\n>>> f(x)\n\nMarkdown is also supported:\n\n```py f(x) ```\n\nAs are reStructuredText literal blocks::\n\nf(x)\n\nAnd reStructuredText code blocks:\n\n.. code-block:: python\n\nf(x) \"\"\" pass ```\n\nIf a code snippet in a docstring contains invalid Python code or if the formatter would otherwise write invalid Python code, then the code example is ignored by the formatter and kept as-is.\n\nCurrently, doctest, Markdown, reStructuredText literal blocks, and reStructuredText code blocks are all supported and automatically recognized. In the case of unlabeled fenced code blocks in Markdown and reStructuredText literal blocks, the contents are assumed to be Python and reformatted. As with any other format, if the contents aren't valid Python, then the block is left untouched automatically.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "docstring-code-line-length": { "description": "Set the line length used when formatting code snippets in docstrings.\n\nThis only has an effect when the `docstring-code-format` setting is enabled.\n\nThe default value for this setting is `\"dynamic\"`, which has the effect of ensuring that any reformatted code examples in docstrings adhere to the global line length configuration that is used for the surrounding Python code. The point of this setting is that it takes the indentation of the docstring into account when reformatting code examples.\n\nAlternatively, this can be set to a fixed integer, which will result in the same line length limit being applied to all reformatted code examples in docstrings. When set to a fixed integer, the indent of the docstring is not taken into account. That is, this may result in lines in the reformatted code example that exceed the globally configured line length limit.\n\nFor example, when this is set to `20` and `docstring-code-format` is enabled, then this code:\n\n```python def f(x): ''' Something about `f`. And an example:\n\n.. code-block:: python\n\nfoo, bar, quux = this_is_a_long_line(lion, hippo, lemur, bear) ''' pass ```\n\n... will be reformatted (assuming the rest of the options are set to their defaults) as:\n\n```python def f(x): \"\"\" Something about `f`. And an example:\n\n.. code-block:: python\n\n( foo, bar, quux, ) = this_is_a_long_line( lion, hippo, lemur, bear, ) \"\"\" pass ```", @@ -1124,7 +1366,10 @@ }, "exclude": { "description": "A list of file patterns to exclude from formatting in addition to the files excluded globally (see [`exclude`](#exclude), and [`extend-exclude`](#extend-exclude)).\n\nExclusions are based on globs, and can be either:\n\n- Single-path patterns, like `.mypy_cache` (to exclude any directory named `.mypy_cache` in the tree), `foo.py` (to exclude any file named `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ). - Relative patterns, like `directory/foo.py` (to exclude that specific file) or `directory/*.py` (to exclude any Python files in `directory`). Note that these paths are relative to the project root (e.g., the directory containing your `pyproject.toml`).\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1153,7 +1398,10 @@ }, "preview": { "description": "Whether to enable the unstable preview style formatting.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "quote-style": { "description": "Configures the preferred quote character for strings. The recommended options are\n\n* `double` (default): Use double quotes `\"` * `single`: Use single quotes `'`\n\nIn compliance with [PEP 8](https://peps.python.org/pep-0008/) and [PEP 257](https://peps.python.org/pep-0257/), Ruff prefers double quotes for triple quoted strings and docstrings even when using `quote-style = \"single\"`.\n\nRuff deviates from using the configured quotes if doing so prevents the need for escaping quote characters inside the string:\n\n```python a = \"a string without any quotes\" b = \"It's monday morning\" ```\n\nRuff will change the quotes of the string assigned to `a` to single quotes when using `quote-style = \"single\"`. However, ruff uses double quotes for he string assigned to `b` because using single quotes would require escaping the `'`, which leads to the less readable code: `'It\\'s monday morning'`.\n\nIn addition, Ruff supports the quote style `preserve` for projects that already use a mixture of single and double quotes and can't migrate to the `double` or `single` style. The quote style `preserve` leaves the quotes of all strings unchanged.", @@ -1168,7 +1416,10 @@ }, "skip-magic-trailing-comma": { "description": "Ruff uses existing trailing commas as an indication that short lines should be left separate. If this option is set to `true`, the magic trailing comma is ignored.\n\nFor example, Ruff leaves the arguments separate even though collapsing the arguments to a single line doesn't exceed the line length if `skip-magic-trailing-comma = false`:\n\n```python # The arguments remain on separate lines because of the trailing comma after `b` def test( a, b, ): pass ```\n\nSetting `skip-magic-trailing-comma = true` changes the formatting to:\n\n```python # The arguments remain on separate lines because of the trailing comma after `b` def test(a, b): pass ```", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -1198,12 +1449,16 @@ { "description": "Use tabs to indent code.", "type": "string", - "enum": ["tab"] + "enum": [ + "tab" + ] }, { "description": "Use [`IndentWidth`] spaces to indent code.", "type": "string", - "enum": ["space"] + "enum": [ + "space" + ] } ] }, @@ -1218,22 +1473,34 @@ "properties": { "case-sensitive": { "description": "Sort imports taking into account case sensitivity.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "classes": { "description": "An override list of tokens to always recognize as a Class for `order-by-type` regardless of casing.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "combine-as-imports": { "description": "Combines as imports on the same line. See isort's [`combine-as-imports`](https://pycqa.github.io/isort/docs/configuration/options.html#combine-as-imports) option.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "constants": { "description": "An override list of tokens to always recognize as a CONSTANT for `order-by-type` regardless of casing.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1251,99 +1518,153 @@ }, "detect-same-package": { "description": "Whether to automatically mark imports from within the same package as first-party. For example, when `detect-same-package = true`, then when analyzing files within the `foo` package, any imports from within the `foo` package will be considered first-party.\n\nThis heuristic is often unnecessary when `src` is configured to detect all first-party sources; however, if `src` is _not_ configured, this heuristic can be useful to detect first-party imports from _within_ (but not _across_) first-party packages.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "extra-standard-library": { "description": "A list of modules to consider standard-library, in addition to those known to Ruff in advance.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "force-single-line": { "description": "Forces all from imports to appear on their own line.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "force-sort-within-sections": { "description": "Don't sort straight-style imports (like `import sys`) before from-style imports (like `from itertools import groupby`). Instead, sort the imports by module, independent of import style.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "force-to-top": { "description": "Force specific imports to the top of their appropriate section.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "force-wrap-aliases": { "description": "Force `import from` statements with multiple members and at least one alias (e.g., `import A as B`) to wrap such that every line contains exactly one member. For example, this formatting would be retained, rather than condensing to a single line:\n\n```python from .utils import ( test_directory as test_directory, test_id as test_id ) ```\n\nNote that this setting is only effective when combined with `combine-as-imports = true`. When `combine-as-imports` isn't enabled, every aliased `import from` will be given its own line, in which case, wrapping is not necessary.\n\nWhen using the formatter, ensure that `format.skip-magic-trailing-comma` is set to `false` (default) when enabling `force-wrap-aliases` to avoid that the formatter collapses members if they all fit on a single line.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "forced-separate": { "description": "A list of modules to separate into auxiliary block(s) of imports, in the order specified.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "from-first": { "description": "Whether to place `import from` imports before straight imports when sorting.\n\nFor example, by default, imports will be sorted such that straight imports appear before `import from` imports, as in: ```python import os import sys from typing import List ```\n\nSetting `from-first = true` will instead sort such that `import from` imports appear before straight imports, as in: ```python from typing import List import os import sys ```", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "known-first-party": { "description": "A list of modules to consider first-party, regardless of whether they can be identified as such via introspection of the local filesystem.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "known-local-folder": { "description": "A list of modules to consider being a local folder. Generally, this is reserved for relative imports (`from . import module`).\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "known-third-party": { "description": "A list of modules to consider third-party, regardless of whether they can be identified as such via introspection of the local filesystem.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "length-sort": { "description": "Sort imports by their string length, such that shorter imports appear before longer imports. For example, by default, imports will be sorted alphabetically, as in: ```python import collections import os ```\n\nSetting `length-sort = true` will instead sort such that shorter imports appear before longer imports, as in: ```python import os import collections ```", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "length-sort-straight": { "description": "Sort straight imports by their string length. Similar to `length-sort`, but applies only to straight imports and doesn't affect `from` imports.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "lines-after-imports": { "description": "The number of blank lines to place after imports. Use `-1` for automatic determination.\n\nRuff uses at most one blank line after imports in typing stub files (files with `.pyi` extension) in accordance to the typing style recommendations ([source](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines)).\n\nWhen using the formatter, only the values `-1`, `1`, and `2` are compatible because it enforces at least one empty and at most two empty lines after imports.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "int" }, "lines-between-types": { "description": "The number of lines to place between \"direct\" and `import from` imports.\n\nWhen using the formatter, only the values `0` and `1` are compatible because it preserves up to one empty line after imports in nested blocks.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "no-lines-before": { "description": "A list of sections that should _not_ be delineated from the previous section via empty lines.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/ImportSection" } }, "no-sections": { "description": "Put all imports into the same section bucket.\n\nFor example, rather than separating standard library and third-party imports, as in: ```python import os import sys\n\nimport numpy import pandas ```\n\nSetting `no-sections = true` will instead group all imports into a single section: ```python import os import numpy import pandas import sys ```", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "order-by-type": { "description": "Order imports by type, which is determined by case, in addition to alphabetically.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "relative-imports-order": { "description": "Whether to place \"closer\" imports (fewer `.` characters, most local) before \"further\" imports (more `.` characters, least local), or vice versa.\n\nThe default (\"furthest-to-closest\") is equivalent to isort's `reverse-relative` default (`reverse-relative = false`); setting this to \"closest-to-furthest\" is equivalent to isort's `reverse-relative = true`.", @@ -1358,21 +1679,30 @@ }, "required-imports": { "description": "Add the specified import line to all files.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "section-order": { "description": "Override in which order the sections should be output. Can be used to move custom sections.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/ImportSection" } }, "sections": { "description": "A list of mappings from section names to modules.\n\nBy default, imports are categorized according to their type (e.g., `future`, `third-party`, and so on). This setting allows you to group modules into custom sections, to augment or override the built-in sections.\n\nFor example, to group all testing utilities, you could create a `testing` section: ```toml testing = [\"pytest\", \"hypothesis\"] ```\n\nThe values in the list are treated as glob patterns. For example, to match all packages in the LangChain ecosystem (`langchain-core`, `langchain-openai`, etc.): ```toml langchain = [\"langchain-*\"] ```\n\nCustom sections should typically be inserted into the `section-order` list to ensure that they're displayed as a standalone group and in the intended order, as in: ```toml section-order = [ \"future\", \"standard-library\", \"third-party\", \"first-party\", \"local-folder\", \"testing\" ] ```\n\nIf a custom section is omitted from `section-order`, imports in that section will be assigned to the `default-section` (which defaults to `third-party`).", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "array", "items": { @@ -1382,18 +1712,27 @@ }, "single-line-exclusions": { "description": "One or more modules to exclude from the single line rule.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "split-on-trailing-comma": { "description": "If a comma is placed after the last member in a multi-line import, then the imports will never be folded into one line.\n\nSee isort's [`split-on-trailing-comma`](https://pycqa.github.io/isort/docs/configuration/options.html#split-on-trailing-comma) option.\n\nWhen using the formatter, ensure that `format.skip-magic-trailing-comma` is set to `false` (default) when enabling `split-on-trailing-comma` to avoid that the formatter removes the trailing commas.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "variables": { "description": "An override list of tokens to always recognize as a var for `order-by-type` regardless of casing.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1406,22 +1745,30 @@ { "description": "The newline style is detected automatically on a file per file basis. Files with mixed line endings will be converted to the first detected line ending. Defaults to [`LineEnding::Lf`] for a files that contain no line endings.", "type": "string", - "enum": ["auto"] + "enum": [ + "auto" + ] }, { "description": "Line endings will be converted to `\\n` as is common on Unix.", "type": "string", - "enum": ["lf"] + "enum": [ + "lf" + ] }, { "description": "Line endings will be converted to `\\r\\n` as is common on Windows.", "type": "string", - "enum": ["cr-lf"] + "enum": [ + "cr-lf" + ] }, { "description": "Line endings will be converted to `\\n` on Unix and `\\r\\n` on Windows.", "type": "string", - "enum": ["native"] + "enum": [ + "native" + ] } ] }, @@ -1444,7 +1791,10 @@ "properties": { "allowed-confusables": { "description": "A list of allowed \"confusable\" Unicode characters to ignore when enforcing `RUF001`, `RUF002`, and `RUF003`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string", "maxLength": 1, @@ -1453,22 +1803,34 @@ }, "dummy-variable-rgx": { "description": "A regular expression used to identify \"dummy\" variables, or those which should be ignored when enforcing (e.g.) unused-variable rules. The default expression matches `_`, `__`, and `_var`, but not `_var_`.", - "type": ["string", "null"] + "type": [ + "string", + "null" + ] }, "exclude": { "description": "A list of file patterns to exclude from linting in addition to the files excluded globally (see [`exclude`](#exclude), and [`extend-exclude`](#extend-exclude)).\n\nExclusions are based on globs, and can be either:\n\n- Single-path patterns, like `.mypy_cache` (to exclude any directory named `.mypy_cache` in the tree), `foo.py` (to exclude any file named `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ). - Relative patterns, like `directory/foo.py` (to exclude that specific file) or `directory/*.py` (to exclude any Python files in `directory`). Note that these paths are relative to the project root (e.g., the directory containing your `pyproject.toml`).\n\nFor more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "explicit-preview-rules": { "description": "Whether to require exact codes to select preview rules. When enabled, preview rules will not be selected by prefixes — the full code of each preview rule will be required to enable the rule.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "extend-fixable": { "description": "A list of rule codes or prefixes to consider fixable, in addition to those specified by `fixable`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -1476,14 +1838,20 @@ "extend-ignore": { "description": "A list of rule codes or prefixes to ignore, in addition to those specified by `ignore`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "extend-per-file-ignores": { "description": "A list of mappings from file pattern to rule codes or prefixes to exclude, in addition to any rules excluded by `per-file-ignores`.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "array", "items": { @@ -1493,14 +1861,20 @@ }, "extend-safe-fixes": { "description": "A list of rule codes or prefixes for which unsafe fixes should be considered safe.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "extend-select": { "description": "A list of rule codes or prefixes to enable, in addition to those specified by `select`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -1508,28 +1882,40 @@ "extend-unfixable": { "description": "A list of rule codes or prefixes to consider non-auto-fixable, in addition to those specified by `unfixable`.", "deprecated": true, - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "extend-unsafe-fixes": { "description": "A list of rule codes or prefixes for which safe fixes should be considered unsafe.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "external": { "description": "A list of rule codes or prefixes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "fixable": { "description": "A list of rule codes or prefixes to consider fixable. By default, all rules are considered fixable.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -1723,14 +2109,20 @@ }, "ignore": { "description": "A list of rule codes or prefixes to ignore. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "ignore-init-module-imports": { "description": "Avoid automatically removing unused imports in `__init__.py` files. Such imports will still be flagged, but with a dedicated message suggesting that the import is either added to the module's `__all__` symbol, or re-exported with a redundant alias (e.g., `import os as os`).\n\nThis option is enabled by default, but you can opt-in to removal of imports via an unsafe fix.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "isort": { "description": "Options for the `isort` plugin.", @@ -1745,7 +2137,10 @@ }, "logger-objects": { "description": "A list of objects that should be treated equivalently to a `logging.Logger` object.\n\nThis is useful for ensuring proper diagnostics (e.g., to identify `logging` deprecations and other best-practices) for projects that re-export a `logging.Logger` object from a common module.\n\nFor example, if you have a module `logging_setup.py` with the following contents: ```python import logging\n\nlogger = logging.getLogger(__name__) ```\n\nAdding `\"logging_setup.logger\"` to `logger-objects` will ensure that `logging_setup.logger` is treated as a `logging.Logger` object when imported from other modules (e.g., `from logging_setup import logger`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1774,7 +2169,10 @@ }, "per-file-ignores": { "description": "A list of mappings from file pattern to rule codes or prefixes to exclude, when considering any matching files. An initial '!' negates the file pattern.", - "type": ["object", "null"], + "type": [ + "object", + "null" + ], "additionalProperties": { "type": "array", "items": { @@ -1784,7 +2182,10 @@ }, "preview": { "description": "Whether to enable preview mode. When preview mode is enabled, Ruff will use unstable rules and fixes.", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "pycodestyle": { "description": "Options for the `pycodestyle` plugin.", @@ -1843,28 +2244,40 @@ }, "select": { "description": "A list of rule codes or prefixes to enable. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } }, "task-tags": { "description": "A list of task tags to recognize (e.g., \"TODO\", \"FIXME\", \"XXX\").\n\nComments starting with these tags will be ignored by commented-out code detection (`ERA`), and skipped by line-length rules (`E501`) if `ignore-overlong-task-comments` is set to `true`.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "typing-modules": { "description": "A list of modules whose exports should be treated equivalently to members of the `typing` module.\n\nThis is useful for ensuring proper type annotation inference for projects that re-export `typing` and `typing_extensions` members from a compatibility module. If omitted, any members imported from modules apart from `typing` and `typing_extensions` will be treated as ordinary Python objects.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "unfixable": { "description": "A list of rule codes or prefixes to consider non-fixable.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/RuleSelector" } @@ -1877,7 +2290,10 @@ "properties": { "max-complexity": { "description": "The maximum McCabe complexity to allow before triggering `C901` errors.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 } @@ -1886,43 +2302,65 @@ }, "ParametrizeNameType": { "type": "string", - "enum": ["csv", "tuple", "list"] + "enum": [ + "csv", + "tuple", + "list" + ] }, "ParametrizeValuesRowType": { "type": "string", - "enum": ["tuple", "list"] + "enum": [ + "tuple", + "list" + ] }, "ParametrizeValuesType": { "type": "string", - "enum": ["tuple", "list"] + "enum": [ + "tuple", + "list" + ] }, "Pep8NamingOptions": { "type": "object", "properties": { "classmethod-decorators": { "description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a class method (in addition to the builtin `@classmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list takes a `cls` argument as its first argument.\n\nExpects to receive a list of fully-qualified names (e.g., `pydantic.validator`, rather than `validator`) or alternatively a plain name which is then matched against the last segment in case the decorator itself consists of a dotted name.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "extend-ignore-names": { "description": "Additional names (or patterns) to ignore when considering `pep8-naming` violations, in addition to those included in `ignore-names`\n\nSupports glob patterns. For example, to ignore all names starting with or ending with `_test`, you could use `ignore-names = [\"test_*\", \"*_test\"]`. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "ignore-names": { "description": "A list of names (or patterns) to ignore when considering `pep8-naming` violations.\n\nSupports glob patterns. For example, to ignore all names starting with or ending with `_test`, you could use `ignore-names = [\"test_*\", \"*_test\"]`. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "staticmethod-decorators": { "description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a static method (in addition to the builtin `@staticmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list has no `self` or `cls` argument.\n\nExpects to receive a list of fully-qualified names (e.g., `belay.Device.teardown`, rather than `teardown`) or alternatively a plain name which is then matched against the last segment in case the decorator itself consists of a dotted name.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -1935,7 +2373,10 @@ "properties": { "keep-runtime-typing": { "description": "Whether to avoid PEP 585 (`List[int]` -> `list[int]`) and PEP 604 (`Union[str, int]` -> `str | int`) rewrites even if a file imports `from __future__ import annotations`.\n\nThis setting is only applicable when the target Python version is below 3.9 and 3.10 respectively, and is most commonly used when working with libraries like Pydantic and FastAPI, which rely on the ability to parse type annotations at runtime. The use of `from __future__ import annotations` causes Python to treat the type annotations as strings, which typically allows for the use of language features that appear in later Python versions but are not yet supported by the current version (e.g., `str | int`). However, libraries that rely on runtime type annotations will break if the annotations are incompatible with the current Python version.\n\nFor example, while the following is valid Python 3.8 code due to the presence of `from __future__ import annotations`, the use of `str| int` prior to Python 3.10 will cause Pydantic to raise a `TypeError` at runtime:\n\n```python from __future__ import annotations\n\nimport pydantic\n\nclass Foo(pydantic.BaseModel): bar: str | int ```", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false @@ -1945,7 +2386,10 @@ "properties": { "ignore-overlong-task-comments": { "description": "Whether line-length violations (`E501`) should be triggered for comments starting with `task-tags` (by default: \\[\"TODO\", \"FIXME\", and \"XXX\"\\]).", - "type": ["boolean", "null"] + "type": [ + "boolean", + "null" + ] }, "max-doc-length": { "description": "The maximum line length to allow for [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) violations within documentation (`W505`), including standalone comments. By default, this is set to null which disables reporting violations.\n\nThe length is determined by the number of characters per line, except for lines containing Asian characters or emojis. For these lines, the [unicode width](https://unicode.org/reports/tr11/) of each character is added up to determine the length.\n\nSee the [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) rule for more information.", @@ -1988,14 +2432,20 @@ }, "ignore-decorators": { "description": "Ignore docstrings for functions or methods decorated with the specified fully-qualified decorators.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } }, "property-decorators": { "description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a property (in addition to the builtin `@property` and standard-library `@functools.cached_property`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list can use a non-imperative summary line.", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -2008,7 +2458,10 @@ "properties": { "extend-generics": { "description": "Additional functions or classes to consider generic, such that any subscripts should be treated as type annotation (e.g., `ForeignKey` in `django.db.models.ForeignKey[\"User\"]`.\n\nExpects to receive a list of fully-qualified names (e.g., `django.db.models.ForeignKey`, rather than `ForeignKey`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" } @@ -2021,7 +2474,10 @@ "properties": { "allow-dunder-method-names": { "description": "Dunder methods name to allow, in addition to the default set from the Python standard library (see: `PLW3201`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "type": "string" }, @@ -2029,62 +2485,92 @@ }, "allow-magic-value-types": { "description": "Constant types to ignore when used as \"magic values\" (see: `PLR2004`).", - "type": ["array", "null"], + "type": [ + "array", + "null" + ], "items": { "$ref": "#/definitions/ConstantType" } }, "max-args": { "description": "Maximum number of arguments allowed for a function or method definition (see: `PLR0913`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-bool-expr": { "description": "Maximum number of Boolean expressions allowed within a single `if` statement (see: `PLR0916`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-branches": { "description": "Maximum number of branches allowed for a function or method body (see: `PLR0912`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-locals": { "description": "Maximum number of local variables allowed for a function or method body (see: `PLR0914`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-nested-blocks": { "description": "Maximum number of nested blocks allowed within a function or method body (see: `PLR1702`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-positional-args": { "description": "Maximum number of positional arguments allowed for a function or method definition (see: `PLR0917`).\n\nIf not specified, defaults to the value of `max-args`.", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-public-methods": { "description": "Maximum number of public methods allowed for a class (see: `PLR0904`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-returns": { "description": "Maximum number of return statements allowed for a function or method body (see `PLR0911`)", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 }, "max-statements": { "description": "Maximum number of statements allowed for a function or method body (see: `PLR0915`).", - "type": ["integer", "null"], + "type": [ + "integer", + "null" + ], "format": "uint", "minimum": 0.0 } @@ -2093,37 +2579,56 @@ }, "PythonVersion": { "type": "string", - "enum": ["py37", "py38", "py39", "py310", "py311", "py312"] + "enum": [ + "py37", + "py38", + "py39", + "py310", + "py311", + "py312" + ] }, "Quote": { "oneOf": [ { "description": "Use double quotes.", "type": "string", - "enum": ["double"] + "enum": [ + "double" + ] }, { "description": "Use single quotes.", "type": "string", - "enum": ["single"] + "enum": [ + "single" + ] } ] }, "QuoteStyle": { "type": "string", - "enum": ["single", "double", "preserve"] + "enum": [ + "single", + "double", + "preserve" + ] }, "RelativeImportsOrder": { "oneOf": [ { "description": "Place \"closer\" imports (fewer `.` characters, most local) before \"further\" imports (more `.` characters, least local).", "type": "string", - "enum": ["closest-to-furthest"] + "enum": [ + "closest-to-furthest" + ] }, { "description": "Place \"further\" imports (more `.` characters, least local) imports before \"closer\" imports (fewer `.` characters, most local).", "type": "string", - "enum": ["furthest-to-closest"] + "enum": [ + "furthest-to-closest" + ] } ] }, @@ -3443,14 +3948,18 @@ { "description": "Ban imports that extend into the parent module or beyond.", "type": "string", - "enum": ["parents"] + "enum": [ + "parents" + ] }, { "description": "Ban all relative imports.", "type": "string", - "enum": ["all"] + "enum": [ + "all" + ] } ] } } -} +} \ No newline at end of file