python icon indicating copy to clipboard operation
python copied to clipboard

Add to_dict method to ResourceField

Open 0xFelix opened this issue 2 years ago • 3 comments

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

0xFelix avatar Sep 12 '22 14:09 0xFelix

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:

k8s-ci-robot avatar Sep 12 '22 14:09 k8s-ci-robot

[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.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Sep 12 '22 14:09 k8s-ci-robot

/assign @fabianvf

roycaihw avatar Sep 12 '22 16:09 roycaihw

@fabianvf Ping

0xFelix avatar Oct 07 '22 13:10 0xFelix

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 avatar Oct 10 '22 17:10 pmareke

@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 avatar Oct 11 '22 08:10 0xFelix

@0xFelix I mean just invert the order of the methods:

Move the to_dict (from line 403 to line 393) method above the __serialize

image

pmareke avatar Oct 11 '22 12:10 pmareke

@pmareke Sorry, got it!

0xFelix avatar Oct 14 '22 07:10 0xFelix

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 avatar Oct 14 '22 18:10 pmareke

@pmareke Done!

0xFelix avatar Oct 17 '22 07:10 0xFelix

Ping @roycaihw @pmareke

0xFelix avatar Nov 16 '22 13:11 0xFelix

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

k8s-triage-robot avatar Feb 14 '23 13:02 k8s-triage-robot

/remove-lifecycle stale

Ping @roycaihw @pmareke

0xFelix avatar Feb 14 '23 14:02 0xFelix

/remove-lifecycle stale

Ping @roycaihw @pmareke

Hi! My comment was just a suggestion, please @roycaihw go ahead.

pmareke avatar Feb 15 '23 06:02 pmareke

/lgtm /approve Thank you!

roycaihw avatar Feb 25 '23 02:02 roycaihw

[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

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Feb 25 '23 02:02 k8s-ci-robot