Draft: Update python generator with correct mypy types and remove sync endpoints in async generator#15878
Draft: Update python generator with correct mypy types and remove sync endpoints in async generator#15878Jay-Madden wants to merge 4 commits intoOpenAPITools:masterfrom
Conversation
|
my first suggestion is to move |
|
FYI @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @arun-nalla (2019/11) @spacether (2019/11) @krjakbrjak (2023/02) |
|
pydnatic also comes with a Mypy plugin: https://docs.pydantic.dev/latest/mypy_plugin/ have you evaluated it? would it help in our case? |
|
I have been testing with the mypy plugin enabled I should probably go ahead and add that configuration to the pyproject.toml, sadly it doesn't address the primary problem which is the fact that it doesn't understand the Constrained types https://docs.pydantic.dev/latest/usage/types/#constrained-types Example: Plugin Enabled from pydantic import BaseModel, StrictStr, conlist
class Foo(BaseModel):
bar: conlist(int, min_items=3) = [1]Further more comprehensive discussion here about using Annotated as well which works for all cases except nested constraints on pydantic<2 which is why we have the rather verbose and ugly |
I can do this, its included here because the interactions between the sync/async endpoints is incredibly confusing type wise, its sort of warping the intended use of async/await syntax and doesn't translate well to static typing at all. |
what about an option (e.g. supportMypy) to let users choose whether they need Mypy support or not ? I would imagine some users like to have it enabled while other prefers the output without Mypy. |
We could do that for sure, but honestly i cant really think of a time you DONT want mypy types in your project because even if you dont use mypy yourself you still get accurate autocomplete etc within your project |
|
We can also use annotated for all cases except the nested conlist case which removes like 90% of the typechecking checks |
@Jay-Madden I wonder if you can file a new PR just for this change so that we can get this enhancement included in the upcoming release. |
|
@Jay-Madden I'm also interested to have these 2 topics moving forward (removing the sync call + adding type information to the generated code) and I can dedicate some time on these tasks, is there anything I can do to help here? I'd be happy to extract the code to remove the sync calls and make it into a dedicated PR for instance. |
yes, please file a PR to start with. |
|
It's in #16601, thanks @Jay-Madden for the initial cleanup! |
|
I made an initial proposition in #16624 to improve all the generated types. @Jay-Madden feel free to close this pull request if you don't intend to work on this in the future. |
|
Closing this PR as the work has been extended by others |
Draft pr to update the python generator with mypy types, this also modifies the asyncio generator to remove the sync calls and rely on async all the way through.
Disclaimer: This is very very rough poc code, opening a draft to start the discussion
I have also included a new sample
python-asyncioin the samples folder. Please let me know if this is not desirablecc: @wing328
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(6.3.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)