From fc0b12af12ea9f4c585c6751923caef7cadfa877 Mon Sep 17 00:00:00 2001 From: Mikhail Epifanov Date: Mon, 19 May 2025 23:11:39 +0200 Subject: [PATCH] remove redundant len, and fix optional --- cookbook/connectors/connector.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cookbook/connectors/connector.py b/cookbook/connectors/connector.py index 003b7cf39..3267f5d02 100644 --- a/cookbook/connectors/connector.py +++ b/cookbook/connectors/connector.py @@ -11,10 +11,10 @@ class UserDTO: first_name: Optional[str] @staticmethod - def try_create_from_user(instance: Optional[User]) -> 'UserDTO': + def create_from_user(instance: User) -> 'UserDTO': return UserDTO( username=instance.username, - first_name=instance.first_name if instance.first_name and len(instance.first_name) > 0 else None + first_name=instance.first_name if instance.first_name else None ) @@ -33,10 +33,10 @@ class ShoppingListEntryDTO: return ShoppingListEntryDTO( food_name=instance.food.name, - amount=instance.amount if instance.amount and instance.amount > 0 else None, + amount=instance.amount if instance.amount else None, unit_name=instance.unit.name if instance.unit else None, - base_unit=instance.unit.base_unit if instance.unit and instance.unit.base_unit and len(instance.unit.base_unit) > 0 else None, - created_by=UserDTO.try_create_from_user(instance.created_by), + base_unit=instance.unit.base_unit if instance.unit and instance.unit.base_unit else None, + created_by=UserDTO.create_from_user(instance.created_by), )