mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Avoid PEP 585 rewrites when builtins are shadowed (#3286)
This commit is contained in:
parent
af5f7dbd83
commit
a032b66c2e
3 changed files with 27 additions and 6 deletions
|
@ -28,3 +28,10 @@ def f(x: IList[str]) -> None:
|
||||||
|
|
||||||
def f(x: "List[str]") -> None:
|
def f(x: "List[str]") -> None:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
list = "abc"
|
||||||
|
|
||||||
|
|
||||||
|
def f(x: List[str]) -> None:
|
||||||
|
...
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl AlwaysAutofixableViolation for DeprecatedCollectionType {
|
||||||
|
|
||||||
fn autofix_title(&self) -> String {
|
fn autofix_title(&self) -> String {
|
||||||
let DeprecatedCollectionType { name } = self;
|
let DeprecatedCollectionType { name } = self;
|
||||||
format!("Replace `{name}` with `{}`", name.to_lowercase(),)
|
format!("Replace `{name}` with `{}`", name.to_lowercase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,14 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr) {
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
let binding = binding.to_lowercase();
|
||||||
binding.to_lowercase(),
|
if checker.is_builtin(&binding) {
|
||||||
expr.location,
|
diagnostic.amend(Fix::replacement(
|
||||||
expr.end_location.unwrap(),
|
binding,
|
||||||
));
|
expr.location,
|
||||||
|
expr.end_location.unwrap(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,4 +74,15 @@ expression: diagnostics
|
||||||
row: 25
|
row: 25
|
||||||
column: 14
|
column: 14
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
DeprecatedCollectionType:
|
||||||
|
name: List
|
||||||
|
location:
|
||||||
|
row: 36
|
||||||
|
column: 9
|
||||||
|
end_location:
|
||||||
|
row: 36
|
||||||
|
column: 13
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue