Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 13, 2023
1 parent 8c4f464 commit f645062
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 64 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/flake8_annotations/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use itertools::Itertools;

use ruff_python_ast::helpers::{union, ReturnStatementVisitor};
use ruff_python_ast::helpers::{pep_604_union, ReturnStatementVisitor};
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{self as ast, Expr, ExprContext};
use ruff_python_semantic::analyze::type_inference::{NumberLike, PythonType, ResolvedPythonType};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub(crate) fn auto_return_type(
.collect::<Vec<_>>();

// Wrap in a bitwise union (e.g., `int | float`).
Some(union(&names))
Some(pep_604_union(&names))
}
ResolvedPythonType::Union(_) => None,
ResolvedPythonType::Unknown => None,
Expand Down
20 changes: 10 additions & 10 deletions crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ impl Violation for MissingReturnTypeUndocumentedPublicFunction {
fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return annotation: `{annotation}`"))
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return annotation"))
Some(format!("Add return type annotation"))
}
}
}
Expand Down Expand Up @@ -268,9 +268,9 @@ impl Violation for MissingReturnTypePrivateFunction {
fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return annotation: `{annotation}`"))
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return annotation"))
Some(format!("Add return type annotation"))
}
}
}
Expand Down Expand Up @@ -325,9 +325,9 @@ impl Violation for MissingReturnTypeSpecialMethod {
fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return annotation: `{annotation}`"))
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return annotation"))
Some(format!("Add return type annotation"))
}
}
}
Expand Down Expand Up @@ -373,9 +373,9 @@ impl Violation for MissingReturnTypeStaticMethod {
fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return annotation: `{annotation}`"))
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return annotation"))
Some(format!("Add return type annotation"))
}
}
}
Expand Down Expand Up @@ -421,9 +421,9 @@ impl Violation for MissingReturnTypeClassMethod {
fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return annotation: `{annotation}`"))
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return annotation"))
Some(format!("Add return type annotation"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ allow_overload.py:29:9: ANN201 Missing return type annotation for public functio
| ^^^ ANN201
30 | return i
|
= help: Add return annotation
= help: Add return type annotation


Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ auto_return_type.py:1:5: ANN201 [*] Missing return type annotation for public fu
| ^^^^ ANN201
2 | return 1
|
= help: Add return annotation: `int`
= help: Add return type annotation: `int`

ℹ Unsafe fix
1 |-def func():
Expand All @@ -22,7 +22,7 @@ auto_return_type.py:5:5: ANN201 [*] Missing return type annotation for public fu
| ^^^^ ANN201
6 | return 1.5
|
= help: Add return annotation: `float`
= help: Add return type annotation: `float`

ℹ Unsafe fix
2 2 | return 1
Expand All @@ -41,7 +41,7 @@ auto_return_type.py:9:5: ANN201 [*] Missing return type annotation for public fu
10 | if x > 0:
11 | return 1
|
= help: Add return annotation: `float`
= help: Add return type annotation: `float`

ℹ Unsafe fix
6 6 | return 1.5
Expand All @@ -59,7 +59,7 @@ auto_return_type.py:16:5: ANN201 [*] Missing return type annotation for public f
| ^^^^ ANN201
17 | return True
|
= help: Add return annotation: `bool`
= help: Add return type annotation: `bool`

ℹ Unsafe fix
13 13 | return 1.5
Expand All @@ -78,7 +78,7 @@ auto_return_type.py:20:5: ANN201 [*] Missing return type annotation for public f
21 | if x > 0:
22 | return None
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

ℹ Unsafe fix
17 17 | return True
Expand All @@ -96,7 +96,7 @@ auto_return_type.py:27:5: ANN201 [*] Missing return type annotation for public f
| ^^^^ ANN201
28 | return 1 or 2.5 if x > 0 else 1.5 or "str"
|
= help: Add return annotation: `str | float`
= help: Add return type annotation: `str | float`

ℹ Unsafe fix
24 24 | return
Expand All @@ -114,7 +114,7 @@ auto_return_type.py:31:5: ANN201 [*] Missing return type annotation for public f
| ^^^^ ANN201
32 | return 1 + 2.5 if x > 0 else 1.5 or "str"
|
= help: Add return annotation: `str | float`
= help: Add return type annotation: `str | float`

ℹ Unsafe fix
28 28 | return 1 or 2.5 if x > 0 else 1.5 or "str"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ annotation_presence.py:5:5: ANN201 Missing return type annotation for public fun
| ^^^ ANN201
6 | pass
|
= help: Add return annotation
= help: Add return type annotation

annotation_presence.py:5:9: ANN001 Missing type annotation for function argument `a`
|
Expand All @@ -33,7 +33,7 @@ annotation_presence.py:10:5: ANN201 Missing return type annotation for public fu
| ^^^ ANN201
11 | pass
|
= help: Add return annotation
= help: Add return type annotation

annotation_presence.py:10:17: ANN001 Missing type annotation for function argument `b`
|
Expand All @@ -58,7 +58,7 @@ annotation_presence.py:20:5: ANN201 Missing return type annotation for public fu
| ^^^ ANN201
21 | pass
|
= help: Add return annotation
= help: Add return type annotation

annotation_presence.py:25:5: ANN201 Missing return type annotation for public function `foo`
|
Expand All @@ -67,7 +67,7 @@ annotation_presence.py:25:5: ANN201 Missing return type annotation for public fu
| ^^^ ANN201
26 | pass
|
= help: Add return annotation
= help: Add return type annotation

annotation_presence.py:45:12: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
Expand Down Expand Up @@ -254,7 +254,7 @@ annotation_presence.py:159:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^ ANN204
160 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

ℹ Unsafe fix
156 156 |
Expand All @@ -274,7 +274,7 @@ annotation_presence.py:165:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^ ANN204
166 | print(f"{self.attr=}")
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

ℹ Unsafe fix
162 162 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ignore_fully_untyped.py:24:5: ANN201 Missing return type annotation for public f
| ^^^^^^^^^^^^^^^^^^^^^^^ ANN201
25 | pass
|
= help: Add return annotation
= help: Add return type annotation

ignore_fully_untyped.py:24:37: ANN001 Missing type annotation for function argument `b`
|
Expand All @@ -29,7 +29,7 @@ ignore_fully_untyped.py:32:5: ANN201 Missing return type annotation for public f
| ^^^^^^^^^^^^^^^^^^^^^^^ ANN201
33 | pass
|
= help: Add return annotation
= help: Add return type annotation

ignore_fully_untyped.py:43:9: ANN201 Missing return type annotation for public function `error_typed_self`
|
Expand All @@ -39,6 +39,6 @@ ignore_fully_untyped.py:43:9: ANN201 Missing return type annotation for public f
| ^^^^^^^^^^^^^^^^ ANN201
44 | pass
|
= help: Add return annotation
= help: Add return type annotation


Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mypy_init_return.py:5:9: ANN204 [*] Missing return type annotation for special m
| ^^^^^^^^ ANN204
6 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

Unsafe fix
2 2 |
Expand All @@ -29,7 +29,7 @@ mypy_init_return.py:11:9: ANN204 [*] Missing return type annotation for special
| ^^^^^^^^ ANN204
12 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

Unsafe fix
8 8 |
Expand All @@ -48,7 +48,7 @@ mypy_init_return.py:40:5: ANN202 Missing return type annotation for private func
| ^^^^^^^^ ANN202
41 | ...
|
= help: Add return annotation
= help: Add return type annotation

mypy_init_return.py:47:9: ANN204 [*] Missing return type annotation for special method `__init__`
|
Expand All @@ -58,7 +58,7 @@ mypy_init_return.py:47:9: ANN204 [*] Missing return type annotation for special
| ^^^^^^^^ ANN204
48 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

Unsafe fix
44 44 | # Errorused to be ok for a moment since the mere presence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ simple_magic_methods.py:2:9: ANN204 [*] Missing return type annotation for speci
| ^^^^^^^ ANN204
3 | ...
|
= help: Add return annotation: `str`
= help: Add return type annotation: `str`

Unsafe fix
1 1 | class Foo:
Expand All @@ -26,7 +26,7 @@ simple_magic_methods.py:5:9: ANN204 [*] Missing return type annotation for speci
| ^^^^^^^^ ANN204
6 | ...
|
= help: Add return annotation: `str`
= help: Add return type annotation: `str`

Unsafe fix
2 2 | def __str__(self):
Expand All @@ -46,7 +46,7 @@ simple_magic_methods.py:8:9: ANN204 [*] Missing return type annotation for speci
| ^^^^^^^ ANN204
9 | ...
|
= help: Add return annotation: `int`
= help: Add return type annotation: `int`

Unsafe fix
5 5 | def __repr__(self):
Expand All @@ -66,7 +66,7 @@ simple_magic_methods.py:11:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^^^^^^^ ANN204
12 | ...
|
= help: Add return annotation: `int`
= help: Add return type annotation: `int`

Unsafe fix
8 8 | def __len__(self):
Expand All @@ -86,7 +86,7 @@ simple_magic_methods.py:14:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^ ANN204
15 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

Unsafe fix
11 11 | def __length_hint__(self):
Expand All @@ -106,7 +106,7 @@ simple_magic_methods.py:17:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^ ANN204
18 | ...
|
= help: Add return annotation: `None`
= help: Add return type annotation: `None`

Unsafe fix
14 14 | def __init__(self):
Expand All @@ -126,7 +126,7 @@ simple_magic_methods.py:20:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^ ANN204
21 | ...
|
= help: Add return annotation: `bool`
= help: Add return type annotation: `bool`

Unsafe fix
17 17 | def __del__(self):
Expand All @@ -146,7 +146,7 @@ simple_magic_methods.py:23:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^ ANN204
24 | ...
|
= help: Add return annotation: `bytes`
= help: Add return type annotation: `bytes`

Unsafe fix
20 20 | def __bool__(self):
Expand All @@ -166,7 +166,7 @@ simple_magic_methods.py:26:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^^ ANN204
27 | ...
|
= help: Add return annotation: `str`
= help: Add return type annotation: `str`

Unsafe fix
23 23 | def __bytes__(self):
Expand All @@ -186,7 +186,7 @@ simple_magic_methods.py:29:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^^^^ ANN204
30 | ...
|
= help: Add return annotation: `bool`
= help: Add return type annotation: `bool`

Unsafe fix
26 26 | def __format__(self, format_spec):
Expand All @@ -206,7 +206,7 @@ simple_magic_methods.py:32:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^^^ ANN204
33 | ...
|
= help: Add return annotation: `complex`
= help: Add return type annotation: `complex`

Unsafe fix
29 29 | def __contains__(self, item):
Expand All @@ -226,7 +226,7 @@ simple_magic_methods.py:35:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^ ANN204
36 | ...
|
= help: Add return annotation: `int`
= help: Add return type annotation: `int`

Unsafe fix
32 32 | def __complex__(self):
Expand All @@ -246,7 +246,7 @@ simple_magic_methods.py:38:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^ ANN204
39 | ...
|
= help: Add return annotation: `float`
= help: Add return type annotation: `float`

Unsafe fix
35 35 | def __int__(self):
Expand All @@ -266,7 +266,7 @@ simple_magic_methods.py:41:9: ANN204 [*] Missing return type annotation for spec
| ^^^^^^^^^ ANN204
42 | ...
|
= help: Add return annotation: `int`
= help: Add return type annotation: `int`

Unsafe fix
38 38 | def __float__(self):
Expand Down
Loading

0 comments on commit f645062

Please sign in to comment.