Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions aws_lambda_powertools/event_handler/openapi/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ def _file_has_resolver(file_path: Path, resolver_name: str) -> bool:
return False

for node in ast.walk(tree):
targets = []
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id == resolver_name:
if _is_resolver_call(node.value):
return True
targets = node.targets
elif isinstance(node, ast.AnnAssign):
targets = [node.target]
for target in targets:
if isinstance(target, ast.Name) and target.id == resolver_name:
if _is_resolver_call(node.value):
return True
return False


Expand Down
9 changes: 9 additions & 0 deletions tests/unit/event_handler/openapi/test_openapi_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def test_file_has_resolver_found(tmp_path: Path):
assert _file_has_resolver(handler_file, "app") is True


def test_file_has_resolver_found_with_type_annotation(tmp_path: Path):
handler_file = tmp_path / "handler.py"
handler_file.write_text("""
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
app: APIGatewayRestResolver = APIGatewayRestResolver()
""")
assert _file_has_resolver(handler_file, "app") is True


def test_is_excluded_with_directory_pattern():
root = Path("/project")
assert _is_excluded(Path("/project/tests/handler.py"), root, ["**/tests/**"]) is True
Expand Down