Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Use property getters and setters for validation #100

Open
richcooper95 opened this issue Feb 2, 2022 · 0 comments
Open

Use property getters and setters for validation #100

richcooper95 opened this issue Feb 2, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@richcooper95
Copy link

Describe the bug
To ensure that validation of attributes happens every time they're set, we should use @property getters/setters for attributes requiring validation.

To Reproduce
n/a

Expected behavior
Use @property getters/setters to validate instance attributes - e.g. here:

    def __init__(self, client, order_id):
        """Instantiate an order change request creation."""
        self._client = client
        self._order_id = order_id
        self._slices = []
        OrderChangeRequestCreate._validate_order_id(self._order_id)

    def _validate_order_id(order_id):
        """Set order ID"""
        if type(order_id) is not str:
            raise OrderChangeRequestCreate.InvalidOrderId(order_id)

can be changed to:

    def __init__(self, client, order_id):
        """Instantiate an order change request creation."""
        self.client = client
        self.order_id = order_id
        self.slices = []

    @property
    def order_id(self):
        return self._order_id

    @order_id.setter
    def order_id(self, value):
        if not isinstance(value, str):
            raise OrderChangeRequestCreate.InvalidOrderId(value)

        self._order_id = value

System (please complete the following information):
n/a

Additional context
Could also fix this issue at the same time!

@richcooper95 richcooper95 added the enhancement New feature or request label Feb 2, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant