-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
CodSpeed Performance ReportMerging #1034 will not alter performanceComparing Summary
|
Hey @dave42w 👋 What python version are you using? |
Python 3.12.7 |
@sansyrox Are we ok to merge? |
@@ -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) |
There was a problem hiding this comment.
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.
query_params: Optional[Dict], | ||
request_body: Optional[Dict], | ||
return_annotation: Optional[Dict], |
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dave42w 👋
Thank you for the PR. I just have a few follow up questions 😄
Description
This PR fixes mypy issues in openapi.py
Summary
This PR fixes the following
TypedDict
all
TypedDict
replaced withdict
the python docs don't include any examples of using TypedDict for a variable, only as a class.
mypy 1.13.0 complains about examples like this
query_params: Optional[TypedDict],
so I have changed them all to be likequery_params: Optional[Dict],
All tests still passMyPy error:
Variable "typing.TypedDict" is not valid as a type
This meant changing a few tests from
to
While the tests all pass I'm not sure if the logic of typing.get_type_hints still works for Dict vs TypedDict
missing dict type
def get_path_obj variable openapi_path_object
This wasn't given a type which was causing multiple mypy errors:
all fixed by changing the declaration to:
def get_schema_object local variable properties
same as above. Change declaration to
all the similar warnings are gone
my results
These changes mean that mypy 1.13 finds no warnings in openapi.py
PR Checklist
Please ensure that:
Pre-Commit Instructions: