-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for Pydantic models in stubgen
#19095
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
stubgen
Hello @JelleZijlstra! Hope you're doing well 🙂 |
Hello @hauntsaninja! Hope you're doing well! |
Hi @sobolevn! You're my last hope 🙂 |
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.
Thanks! One main comment :)
test-data/unit/stubgen.test
Outdated
|
||
class User(BaseUser): | ||
name: str | ||
email: str |
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.
email: str | |
email: str = '@' |
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.
There is an issue connected with this change. Currently, the code only sets processing_pydantic_model = True
when the direct base class is pydantic.BaseModel
, but it doesn't handle cases where a class inherits from another class that inherits from pydantic.BaseModel
. I tried a few ideas but they aren't working. Could you please give me a clue how to tackle the problem?
name: str | ||
email: str | ||
|
||
[case testPydanticModelWithMethods] |
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.
We can just add some methods to existing models. Let's reduce the amount of tests without reducing test features.
This PR adds support for generating stubs for Pydantic models in
stubgen
.Changes
pydantic.BaseModel
directly or indirectlyFixes #16968