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

BaseModel's Field definitions to use known-word argument instead of positional argument for default values #699

Closed
AndreLobato opened this issue Jun 29, 2023 · 1 comment · Fixed by #700

Comments

@AndreLobato
Copy link

AndreLobato commented Jun 29, 2023

Is your feature request related to a problem? Please describe.

This is more a coding concern for whom uses VSCode (and maybe other IDEs as well) and are trying to benefit from Pylance's strict type validations. The issue is that Pylance fail to validate Models with default field values when they are defined as a positional argument of Field, for example:

Screenshot from 2023-06-29 15-33-13

In the case of hera models this can be seen as:

Screenshot from 2023-06-29 15-38-39

Describe the solution you'd like

The solution for this is rather simple, just need to declare the default value as known-word argument in the models such as...

Screenshot from 2023-06-29 15-35-51

I understand the models are generated using datamodel-codegen and there's a flag called --use-default-kwarg which I believe will fix this issue

Describe alternatives you've considered

The alternative for the moment is to add a comment in the lines where this occur so type is ignored such as #type: ignore or #pyright: ignore but I wish to keep things clean and as much as possible respect types constrains throughout.

Additional context

This issue or similar were discussed in the pydantic repo as in: pydantic/pydantic#3753 and pydantic/pydantic#3617

Some claim to be a bug, others that is a convoluted problem with the validation libraries... regardless, considering the issue has been closed for more than a year I suspect they are not changing any anytime soon.

@flaviuvadan
Copy link
Collaborator

Thanks for flagging this @AndreLobato! We certainly appreciate the dev ex concern. I will add the flag you suggested and regenerate the models

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants