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

Use property getters and setters for validation #100

@richcooper95

Description

@richcooper95

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions