mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +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:
|
||||
...
|
||||
|
||||
|
||||
list = "abc"
|
||||
|
||||
|
||||
def f(x: List[str]) -> None:
|
||||
...
|
||||
|
|
|
@ -26,7 +26,7 @@ impl AlwaysAutofixableViolation for DeprecatedCollectionType {
|
|||
|
||||
fn autofix_title(&self) -> String {
|
||||
let DeprecatedCollectionType { name } = self;
|
||||
format!("Replace `{name}` with `{}`", name.to_lowercase(),)
|
||||
format!("Replace `{name}` with `{}`", name.to_lowercase())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,12 +43,15 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from_located(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let binding = binding.to_lowercase();
|
||||
if checker.is_builtin(&binding) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
binding.to_lowercase(),
|
||||
binding,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,4 +74,15 @@ expression: diagnostics
|
|||
row: 25
|
||||
column: 14
|
||||
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