feat(Book): strip before save

This commit is contained in:
Kristofers Solo 2023-11-08 15:39:12 +02:00
parent 6410a97e2b
commit ce1c171bb0

View File

@ -18,14 +18,14 @@ def _check_stock_value(instance, attribute, value):
@logger.catch
def _to_isbn(number: str):
return ISBN(number)
return ISBN(number.strip())
@define
class Book:
isbn: ISBN = field(converter=_to_isbn, validator=validators.instance_of(ISBN), on_setattr=setters.frozen, repr=lambda value: f"'{value}'")
title: str = field()
author: str = field()
title: str = field(converter=str.strip)
author: str = field(converter=str.strip)
price: float = field(converter=float, validator=[validators.instance_of(float), _check_price_value])
stock: int = field(converter=int, validator=[validators.instance_of(int), _check_stock_value])