Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy issues in openapi.py with missing dict and use of typedDict #1034

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ pytest
```
- Run only the integration tests
```
pytest
```
For just integration tests use
```
pytest integration_tests
```
```
Expand Down
18 changes: 9 additions & 9 deletions robyn/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from importlib import resources
from inspect import Signature
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, TypedDict
from typing import Any, Callable, Dict, List, Optional, Tuple

from robyn.responses import html
from robyn.robyn import QueryParams, Response
Expand Down Expand Up @@ -236,9 +236,9 @@ def get_path_obj(
name: str,
description: str,
tags: List[str],
query_params: Optional[TypedDict],
request_body: Optional[TypedDict],
return_annotation: Optional[TypedDict],
query_params: Optional[Dict],
request_body: Optional[Dict],
return_annotation: Optional[Dict],
Comment on lines +239 to +241
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error prompted these changes??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check tomorrow.
I think the solution (to follow all the docs I can find) would be to have our own class of TypedDict rather than use TypedDict directly.

) -> Tuple[str, dict]:
"""
Get the "path" openapi object according to spec
Expand All @@ -258,7 +258,7 @@ def get_path_obj(
if not description:
description = "No description provided"

openapi_path_object = {
openapi_path_object: dict = {
"summary": name,
"description": description,
"parameters": [],
Expand Down Expand Up @@ -293,7 +293,7 @@ def get_path_obj(
endpoint_with_path_params_wrapped_in_braces += "/{" + path_param_name + "}"

if query_params:
query_param_annotations = query_params.__annotations__ if query_params is TypedDict else typing.get_type_hints(query_params)
query_param_annotations = query_params.__annotations__ if query_params is Dict else typing.get_type_hints(query_params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these functions wouldn't make sense on a regular dict.


for query_param in query_param_annotations:
query_param_type = self.get_openapi_type(query_param_annotations[query_param])
Expand All @@ -310,7 +310,7 @@ def get_path_obj(
if request_body:
properties = {}

request_body_annotations = request_body.__annotations__ if request_body is TypedDict else typing.get_type_hints(request_body)
request_body_annotations = request_body.__annotations__ if request_body is Dict else typing.get_type_hints(request_body)

for body_item in request_body_annotations:
properties[body_item] = self.get_schema_object(body_item, request_body_annotations[body_item])
Expand Down Expand Up @@ -339,7 +339,7 @@ def get_path_obj(

return endpoint_with_path_params_wrapped_in_braces, openapi_path_object

def get_openapi_type(self, typed_dict: TypedDict) -> str:
def get_openapi_type(self, typed_dict: Dict) -> str:
"""
Get actual type from the TypedDict annotations

Expand Down Expand Up @@ -371,7 +371,7 @@ def get_schema_object(self, parameter: str, param_type: Any) -> dict:
@return: dict the properties object
"""

properties = {
properties: dict = {
"title": parameter.capitalize(),
}

Expand Down
Loading