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

Add __init__ for pydantic classes #35

Closed
Nathan-Nesbitt opened this issue Sep 27, 2021 · 3 comments
Closed

Add __init__ for pydantic classes #35

Nathan-Nesbitt opened this issue Sep 27, 2021 · 3 comments
Labels
Type: Enhancement New feature or request

Comments

@Nathan-Nesbitt
Copy link
Contributor

Based on some comments.

As Pydantic doesn't display the variables that are defined in the class:

Screenshot from 2021-09-27 06-32-48

We can add the __init__ to each of the classes which would allow for VSCode to pick up on what parameters the class takes. This would reduce the time required to look at the docs for required parameters, but would require more code in each class.

@Nathan-Nesbitt Nathan-Nesbitt added the Type: Enhancement New feature or request label Sep 27, 2021
@hillairet
Copy link
Member

hillairet commented Sep 27, 2021

So you can do either:

    def __init__(self, **data):
        """My modified docstring"""
        super().__init__(**data)

Or:

ExampleModel.__init__.__doc__ = 'My modified docstring'

I suspect the latter will not be picked up by VSCode though

@Nathan-Nesbitt
Copy link
Contributor Author

I will try out the first one, but I will show you what I was hoping to achieve:

This is with nothing
image

This is with the first solution
image

This is what I was hoping to achieve
image

I think there may be a different way of solving the input types using pylance based on this PR but I haven't gotten it working yet.

@Nathan-Nesbitt
Copy link
Contributor Author

Nathan-Nesbitt commented Sep 29, 2021

Found a way, unfortunately based on that PR the proper solution to this will not be available until a new standard has been adapted in python. The solution involves making changes to pydantics source and works remarkably well. The following is using the changes defined in that link, along with pylance:

image

No need for the __init__.

The interesting part is that the pydantic repo actually already contains these changes but there hasn't been a release since may.

We can install from GIT instead of PYPI and it works:

pip install git+git://github.com/samuelcolvin/pydantic@master#egg=pydantic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants