mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
Add required space to UP006 and UP007 fixes (#7202)
We're removing a set of brackets here so we need to pad the fix. Closes https://github.com/astral-sh/ruff/issues/7201.
This commit is contained in:
parent
171b66cb43
commit
c1af1c291d
3 changed files with 40 additions and 3 deletions
|
@ -103,3 +103,8 @@ class ServiceRefOrValue:
|
|||
list[ServiceSpecificationRef]
|
||||
| list[ServiceSpecification]
|
||||
] = None
|
||||
|
||||
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7201
|
||||
class ServiceRefOrValue:
|
||||
service_specification: Optional[str]is not True = None
|
||||
|
|
|
@ -4,6 +4,7 @@ use ruff_python_ast::{self as ast, Constant, Expr, ExprContext, Operator};
|
|||
use ruff_python_semantic::analyze::typing::Pep604Operator;
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix::edits::pad;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
|
@ -79,7 +80,11 @@ pub(crate) fn use_pep604_annotation(
|
|||
}
|
||||
_ => {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().expr(&optional(slice)),
|
||||
pad(
|
||||
checker.generator().expr(&optional(slice)),
|
||||
expr.range(),
|
||||
checker.locator(),
|
||||
),
|
||||
expr.range(),
|
||||
)));
|
||||
}
|
||||
|
@ -96,14 +101,22 @@ pub(crate) fn use_pep604_annotation(
|
|||
}
|
||||
Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().expr(&union(elts)),
|
||||
pad(
|
||||
checker.generator().expr(&union(elts)),
|
||||
expr.range(),
|
||||
checker.locator(),
|
||||
),
|
||||
expr.range(),
|
||||
)));
|
||||
}
|
||||
_ => {
|
||||
// Single argument.
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.locator().slice(slice).to_string(),
|
||||
pad(
|
||||
checker.locator().slice(slice).to_string(),
|
||||
expr.range(),
|
||||
checker.locator(),
|
||||
),
|
||||
expr.range(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -391,5 +391,24 @@ UP007.py:102:28: UP007 [*] Use `X | Y` for type annotations
|
|||
104 |- | list[ServiceSpecification]
|
||||
105 |- ] = None
|
||||
102 |+ service_specification: list[ServiceSpecificationRef] | list[ServiceSpecification] | None = None
|
||||
106 103 |
|
||||
107 104 |
|
||||
108 105 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
|
||||
|
||||
UP007.py:110:28: UP007 [*] Use `X | Y` for type annotations
|
||||
|
|
||||
108 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
|
||||
109 | class ServiceRefOrValue:
|
||||
110 | service_specification: Optional[str]is not True = None
|
||||
| ^^^^^^^^^^^^^ UP007
|
||||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
107 107 |
|
||||
108 108 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
|
||||
109 109 | class ServiceRefOrValue:
|
||||
110 |- service_specification: Optional[str]is not True = None
|
||||
110 |+ service_specification: str | None is not True = None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue