Skip to content

Commit b5ccaad

Browse files
committed
Support finding type annotated resolver
1 parent 80f9edd commit b5ccaad

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

aws_lambda_powertools/event_handler/openapi/merge.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ def _file_has_resolver(file_path: Path, resolver_name: str) -> bool:
6767
return False
6868

6969
for node in ast.walk(tree):
70+
targets = []
7071
if isinstance(node, ast.Assign):
71-
for target in node.targets:
72-
if isinstance(target, ast.Name) and target.id == resolver_name:
73-
if _is_resolver_call(node.value):
74-
return True
72+
targets = node.targets
73+
elif isinstance(node, ast.AnnAssign):
74+
targets = [node.target]
75+
for target in targets:
76+
if isinstance(target, ast.Name) and target.id == resolver_name:
77+
if _is_resolver_call(node.value):
78+
return True
7579
return False
7680

7781

tests/unit/event_handler/openapi/test_openapi_merge.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ def test_file_has_resolver_found(tmp_path: Path):
5757
assert _file_has_resolver(handler_file, "app") is True
5858

5959

60+
def test_file_has_resolver_found_with_type_annotation(tmp_path: Path):
61+
handler_file = tmp_path / "handler.py"
62+
handler_file.write_text("""
63+
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
64+
app: APIGatewayRestResolver = APIGatewayRestResolver()
65+
""")
66+
assert _file_has_resolver(handler_file, "app") is True
67+
68+
6069
def test_is_excluded_with_directory_pattern():
6170
root = Path("/project")
6271
assert _is_excluded(Path("/project/tests/handler.py"), root, ["**/tests/**"]) is True

0 commit comments

Comments
 (0)