-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove pydantic-yaml
as dependency
#110
Conversation
e49fc5b
to
d9edeb4
Compare
from io import StringIO | ||
|
||
from pydantic import TypeAdapter | ||
from ruamel.yaml import YAML |
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.
Why importing locally to the function? This will be executed each time the function is called.
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.
So I kind of imitated the style before. I think @DropD introduced this in a PR. My understanding is that this is only loaded if the function is called (and then cached so rerunning is not an issue). This makes it faster to do a top level import (import sirocco
) since not all dependencies that are used in the library are immediately loaded. I am not sure about a guideline here. It makes sense to do it for ruamel
since it will be only needed in a few places and importing it can take some time, but if for TypeAdapter
and StringIO
I am not sure if makes such a difference. Maybe @DropD has a comment or correction.
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.
Also, it hides in the function what the module depends on. Curious about @DropD thoughts on that.
Other than my small comment I'm fine with the PR. I thought Also may I ask why |
I just used the library that pydantic-yaml was using. We have now the flexibility to change it but I did not investigate the differences. Since it is used with particular options |
Thanks for the explanation but don't bother, this is really low priority. |
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.
LGTM
We decided to move the imports to the header for better overview, the advantage of not importing |
The amount of functionality we use of this library is extremly minimal. We replace it with the dependency `ruamel.yaml` that parses the yaml file into a python object. Furthemorer, the library still uses pydantic API v1 for validating the pydantic model which is deprecated so we can replace it with pydantic v2. In addition this change gives us more flexibility as it separates the parsing of the yaml file and the validation through pydantic. To have a similar utility function that can be used in the docstring tests we implement `validate_yaml_content`.
d9edeb4
to
ca4f892
Compare
The amount of functionality we use of this library is extremely minimal. We replace it with the dependency
ruamel.yaml
that parses the yaml file into a python object. This is basically the code we use from the dependency https://github.com/NowanIlfideme/pydantic-yaml/blob/130569dabbe9843771bc6f7d52830e061238d61b/src/pydantic_yaml/_internals/v2.py#L217-L242Furthermore, the library still uses pydantic API v1 for validating the pydantic model which is deprecated so we can replace it with pydantic v2. In addition this change gives us more flexibility as it separates the parsing of the yaml file and the validation through pydantic.
To have a similar utility function that can be used in the docstring tests we implement
validate_yaml_content
.