This commit is contained in:
Charlie Marsh 2023-07-20 15:37:06 -04:00
parent bcec2f0c4c
commit b6d41b9560
3 changed files with 955 additions and 951 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,6 @@
---
source: crates/ruff/src/rules/flake8_future_annotations/mod.rs
---
no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union
|
1 | def main() -> None:
2 | a_list: list[str] | None = []
| ^^^^^^^^^^^^^^^^ FA102
3 | a_list.append("hello")
|
no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection
|
1 | def main() -> None:
@ -17,11 +9,12 @@ no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annot
3 | a_list.append("hello")
|
no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union
no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union
|
6 | def hello(y: dict[str, int] | None) -> None:
| ^^^^^^^^^^^^^^^^^^^^^ FA102
7 | del y
1 | def main() -> None:
2 | a_list: list[str] | None = []
| ^^^^^^^^^^^^^^^^ FA102
3 | a_list.append("hello")
|
no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection
@ -31,4 +24,11 @@ no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annot
7 | del y
|
no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union
|
6 | def hello(y: dict[str, int] | None) -> None:
| ^^^^^^^^^^^^^^^^^^^^^ FA102
7 | del y
|

View File

@ -113,7 +113,11 @@ pub(crate) fn lambda_assignment(
// See: https://github.com/astral-sh/ruff/issues/3046
// See: https://github.com/astral-sh/ruff/issues/5421
if (annotation.is_some() && checker.semantic().scope().kind.is_class())
|| checker.semantic().scope().has(id)
|| checker
.semantic()
.scope()
.get_all(id)
.any(|binding_id| checker.semantic().binding(binding_id).kind.is_annotation())
{
diagnostic.set_fix(Fix::manual(Edit::range_replacement(indented, stmt.range())));
} else {
@ -139,9 +143,9 @@ fn extract_types(annotation: &Expr, semantic: &SemanticModel) -> Option<(Vec<Exp
let Expr::Tuple(ast::ExprTuple { elts, .. }) = slice.as_ref() else {
return None;
};
if elts.len() != 2 {
let [param_types, return_type] = elts.as_slice() else {
return None;
}
};
if !semantic
.resolve_call_path(value)
@ -155,7 +159,7 @@ fn extract_types(annotation: &Expr, semantic: &SemanticModel) -> Option<(Vec<Exp
// The first argument to `Callable` must be a list of types, parameter
// specification, or ellipsis.
let args = match &elts[0] {
let params = match param_types {
Expr::List(ast::ExprList { elts, .. }) => elts.clone(),
Expr::Constant(ast::ExprConstant {
value: Constant::Ellipsis,
@ -165,9 +169,9 @@ fn extract_types(annotation: &Expr, semantic: &SemanticModel) -> Option<(Vec<Exp
};
// The second argument to `Callable` must be a type.
let return_type = elts[1].clone();
let return_type = return_type.clone();
Some((args, return_type))
Some((params, return_type))
}
fn function(