Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 10, 2023
1 parent 61ed3ff commit 1f9910b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Type
from typing import Annotated, Any, Optional, Type, Union
from typing_extensions import override

# Error
Expand Down Expand Up @@ -95,27 +95,27 @@ def foo(self: "Foo", a: int, *params: Any, **options: str) -> int:
def foo(self: "Foo", a: int, *params: str, **options: Any) -> int:
pass

# ANN401
# OK
@override
def foo(self: "Foo", a: Any, *params: str, **options: str) -> int:
pass

# ANN401
# OK
@override
def foo(self: "Foo", a: int, *params: str, **options: str) -> Any:
pass

# ANN401
# OK
@override
def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int:
pass

# ANN401
# OK
@override
def foo(self: "Foo", a: int, *params: Any, **options: str) -> int:
pass

# ANN401
# OK
@override
def foo(self: "Foo", a: int, *params: str, **options: Any) -> int:
pass
Expand All @@ -137,3 +137,17 @@ def foo(self, /, a: int, b: int) -> int:

# OK
def f(*args: *tuple[int]) -> None: ...
def f(a: object) -> None: ...
def f(a: str | bytes) -> None: ...
def f(a: Union[str, bytes]) -> None: ...
def f(a: Optional[str]) -> None: ...
def f(a: Annotated[str, ...]) -> None: ...
def f(a: "Union[str, bytes]") -> None: ...

# ANN401
def f(a: Any | int) -> None: ...
def f(a: int | Any) -> None: ...
def f(a: Union[str, bytes, Any]) -> None: ...
def f(a: Optional[Any]) -> None: ...
def f(a: Annotated[Any, ...]) -> None: ...
def f(a: "Union[str, bytes, Any]") -> None: ...
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/flake8_annotations/rules/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ fn check_dynamically_typed<F>(
}) = annotation
{
// Quoted annotations
if let Ok((annotation, _)) = parse_type_annotation(string, *range, checker.locator) {
if let Ok((parsed_annotation, _)) = parse_type_annotation(string, *range, checker.locator) {
if type_hint_resolves_to_any(
&annotation,
&parsed_annotation,
checker.semantic(),
checker.locator,
checker.settings.target_version.minor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,60 @@ annotation_presence.py:134:13: ANN101 Missing type annotation for `self` in meth
135 | pass
|

annotation_presence.py:148:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
147 | # ANN401
148 | def f(a: Any | int) -> None: ...
| ^^^^^^^^^ ANN401
149 | def f(a: int | Any) -> None: ...
150 | def f(a: Union[str, bytes, Any]) -> None: ...
|

annotation_presence.py:149:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
147 | # ANN401
148 | def f(a: Any | int) -> None: ...
149 | def f(a: int | Any) -> None: ...
| ^^^^^^^^^ ANN401
150 | def f(a: Union[str, bytes, Any]) -> None: ...
151 | def f(a: Optional[Any]) -> None: ...
|

annotation_presence.py:150:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
148 | def f(a: Any | int) -> None: ...
149 | def f(a: int | Any) -> None: ...
150 | def f(a: Union[str, bytes, Any]) -> None: ...
| ^^^^^^^^^^^^^^^^^^^^^^ ANN401
151 | def f(a: Optional[Any]) -> None: ...
152 | def f(a: Annotated[Any, ...]) -> None: ...
|

annotation_presence.py:151:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
149 | def f(a: int | Any) -> None: ...
150 | def f(a: Union[str, bytes, Any]) -> None: ...
151 | def f(a: Optional[Any]) -> None: ...
| ^^^^^^^^^^^^^ ANN401
152 | def f(a: Annotated[Any, ...]) -> None: ...
153 | def f(a: "Union[str, bytes, Any]") -> None: ...
|

annotation_presence.py:152:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
150 | def f(a: Union[str, bytes, Any]) -> None: ...
151 | def f(a: Optional[Any]) -> None: ...
152 | def f(a: Annotated[Any, ...]) -> None: ...
| ^^^^^^^^^^^^^^^^^^^ ANN401
153 | def f(a: "Union[str, bytes, Any]") -> None: ...
|

annotation_presence.py:153:10: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
|
151 | def f(a: Optional[Any]) -> None: ...
152 | def f(a: Annotated[Any, ...]) -> None: ...
153 | def f(a: "Union[str, bytes, Any]") -> None: ...
| ^^^^^^^^^^^^^^^^^^^^^^^^ ANN401
|


0 comments on commit 1f9910b

Please sign in to comment.