python
python copied to clipboard
Add to_dict method to ResourceField
What type of PR is this?
/kind feature
What this PR does / why we need it:
This allows to recursively convert ResourceFields to dicts.
Does this PR introduce a user-facing change?
Add to_dict method to ResourceField
Welcome @0xFelix!
It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes-client/python has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: 0xFelix
Once this PR has been reviewed and has the lgtm label, please assign roycaihw for approval by writing /assign @roycaihw
in a comment. For more information see:The Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment
/assign @fabianvf
@fabianvf Ping
Sorry @0xFelix and @roycaihw I think is good practice if you put first in the code the to_dict
and later the __serialize
as the first one calls the second and the code is more readable.
Great PR by the way!
@pmareke Thanks! Can you describe this in a little more detail? I'm not sure how you would change it.
__serialize
is called recursively on every ResourceField
beginning with the root object. to_dict
is starting that recursion by calling __serialize
on the root object.
@0xFelix I mean just invert the order of the methods:
Move the to_dict
(from line 403 to line 393) method above the __serialize
@pmareke Sorry, got it!
Great job @0xFelix !!
As you're using returns in each if you can simplify a little bit the method:
def __serialize(self, field):
if isinstance(field, ResourceField):
return {
k: self.__serialize(v) for k, v in field.__dict__.items()
}
if isinstance(field, (list, tuple)):
return [self.__serialize(item) for item in field]
return field
@pmareke Done!
Ping @roycaihw @pmareke
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle stale
- Close this PR with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
/remove-lifecycle stale
Ping @roycaihw @pmareke
/remove-lifecycle stale
Ping @roycaihw @pmareke
Hi! My comment was just a suggestion, please @roycaihw go ahead.
/lgtm /approve Thank you!
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: 0xFelix, roycaihw
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~kubernetes/base/OWNERS~~ [roycaihw]
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment