@property
def password(self):
    return self._password

@password.setter
def password(self, value):
    if not isinstance(value, str):
        raise TypeError('password must be a string')
if len(value) < self.minlen:
    raise ValueError('password must be at least %d character len' % self.minlen
        )
self._password = value
Proper way in Python to raise errors while setting variables