I'm wondering what is the best way to check for input arguments for a defining a class attributes, and performing type checking and value checking. Currently, I'm assigning the attributes and then checking the attributes, rather than checking the input arguments:
class A: def __init__(self, a, b, c): self.a = a self.b = b self.c = c self._check_attr() def _check_attr(self): # check types. if not isinstance(self.a, TypeA): ... if not isinstance(self.b, TypeB): ...
Mainly because I want to use
self._check_attr() to check for type and value using one function. Is this a cleaner way to do so? What is the standard way to ensure type and value safety in a python class?
With reference to Python 3.