-
Notifications
You must be signed in to change notification settings - Fork 1
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
[DEP] Bump Pydantic to V2.6 #116
Conversation
- fix optional fields - fix batch private field (_client): add __init__
- refacto of ordered_jobs attribute creation - add a minimal version for pydantic - apply pydantic conventions - refacto of how to set _client attribute
pasqal_cloud/batch.py
Outdated
@validator("configuration", pre=True) | ||
@jobs.setter | ||
def jobs(self, _: Any) -> None: | ||
# Does not set 'jobs' as it is built from 'ordered_jobs' |
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.
I'm not totally convinced by my explanation, if you have a better manner of explaining it, I am all ears.
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.
What are you trying to explain?
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.
I am trying to explain we can't set jobs as it depending of ordered_jobs, it is just that ordered jobs is a list of dict, and jobs a dict with a different key for each job, made from ordered list. Anyway I might change the logic as it is very confusing, I remember I had to do this trick with the property before Pydantic V2 but things can be easier now. I will have a look.
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.
Quick suggestion, feel free to iterate over it
# Does not set 'jobs' as it is built from 'ordered_jobs' | |
# Override the jobs setter to be a no-op. | |
# `jobs` is a read-only attribute which is derived from the `ordered_jobs` key. |
e6da099
to
68eb594
Compare
c806a0e
to
53546a3
Compare
pasqal_cloud/workload.py
Outdated
def result_link_to_result( | ||
cls, result: Optional[Dict[str, Any]], values: Dict[str, Any] | ||
cls, v: Optional[Dict[str, Any]], info: ValidationInfo |
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 the single letter variable changes?
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.
To match pydantic way of using their feature: https://docs.pydantic.dev/latest/concepts/validators/
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.
As I mentioned above I don't think it's advantageous to use v
rather than being explicit with result
pasqal_cloud/batch.py
Outdated
@validator("configuration", pre=True) | ||
@jobs.setter | ||
def jobs(self, _: Any) -> None: | ||
# Does not set 'jobs' as it is built from 'ordered_jobs' |
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.
What are you trying to explain?
configuration: Union[Dict[str, Any], BaseConfig, None], | ||
values: Dict[str, Any], | ||
v: Union[Dict[str, Any], BaseConfig, None], | ||
info: ValidationInfo, |
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 the variable name changes?
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.
Variable name changed for the same reason as I explained on your first comment, to match Pydantic documentation.
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.
It's ok in the documentation to keep things generic but I think for our purpose here it's more readable and maintainable to keep configuration
and not v
.
pasqal_cloud/batch.py
Outdated
values["ordered_jobs"] = ordered_jobs_list | ||
return values | ||
jobs_received = data.get("jobs", []) | ||
data["ordered_jobs"] = [{**job, "_client": data["_client"]} for job in jobs_received] |
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.
If you really want to reduce this you can replace jobs_received
with data.get("jobs", [])
.
You aren't saving much in the way of readability
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.
I feel like it will be too much in this case if I replace jobs_received, too many information on the same line. I think this format is clear and compact enough. Anyway I think this is more of a question of preference. If you think it is not relevant I can change it.
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.
The 2nd line at a glance is obscure so not sure readability or clarity means anything there. I'm just pointing out you can reduce it further if we want, you do what you prefer
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 aside from the loss of explicitness in the method parameters.
configuration: Union[Dict[str, Any], BaseConfig, None], | ||
values: Dict[str, Any], | ||
v: Union[Dict[str, Any], BaseConfig, None], | ||
info: ValidationInfo, |
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.
It's ok in the documentation to keep things generic but I think for our purpose here it's more readable and maintainable to keep configuration
and not v
.
pasqal_cloud/workload.py
Outdated
def result_link_to_result( | ||
cls, result: Optional[Dict[str, Any]], values: Dict[str, Any] | ||
cls, v: Optional[Dict[str, Any]], info: ValidationInfo |
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.
As I mentioned above I don't think it's advantageous to use v
rather than being explicit with result
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.
Looks good overall, a couple small remarks
pasqal_cloud/batch.py
Outdated
@validator("configuration", pre=True) | ||
@jobs.setter | ||
def jobs(self, _: Any) -> None: | ||
# Does not set 'jobs' as it is built from 'ordered_jobs' |
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.
Quick suggestion, feel free to iterate over it
# Does not set 'jobs' as it is built from 'ordered_jobs' | |
# Override the jobs setter to be a no-op. | |
# `jobs` is a read-only attribute which is derived from the `ordered_jobs` key. |
Description
This PR updates the version of Pydantic required by pasqal-cloud from V1.10 to V2.6.
Breaking changes
Now pasqal-cloud needs Pydantic >= 2.6.0 to run.
Checklist
Versioning (PASQAL developers only)
_version.py
following the changes in your PR and by using semantic versioning.Documentation
Tests
Internal tests pipeline (PASQAL developers only)
If your PR hasn't changed any functionality, it still needs to be validated against internal tests.
After updating the version (PASQAL developers only)