Ejemplo n.º 1
0
class Pet(UserObject, RegistersSubclasses, ABC):
    pet_type: str = UserProperty(str)
    name: str = UserProperty(str)

    @abstractmethod
    def speak(self):
        pass
Ejemplo n.º 2
0
class Vehicle(UserObject):
    color: str = UserProperty(str)
    description: str = UserProperty(str)

    @property
    def license(self):
        return key(self)
Ejemplo n.º 3
0
class Person(UserObject):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str)
    current_address: Address = UserProperty(
        Address, default_function=lambda person: person.previous_addresses[0])
    previous_addresses: List[Address] = ListProperty(Address)
    vehicles: Dict[str, Vehicle] = DictProperty(Vehicle,
                                                key_pattern=r"^[a-f0-9]{6}$",
                                                default={},
                                                persist_defaults=True)
Ejemplo n.º 4
0
class Cat(Pet):
    pet_type: str = UserProperty(SchemaConst("cat"))

    def speak(self):
        return f"{self.name} says Miaow!"
Ejemplo n.º 5
0
class Person(UserObject):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str)
    pets: List[Pet] = UserProperty(SchemaArray(Pet))
Ejemplo n.º 6
0
class Greyhound(Dog):
    pet_type: str = UserProperty(SchemaConst("greyhound"))

    def speak(self):
        return f"{self.name}, the greyhound, says Woof!"
Ejemplo n.º 7
0
class Person(UserObject, ReadsYAML):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str)
    current_address: Address = UserProperty(Address)
    previous_addresses: List[Address] = UserProperty(SchemaArray(Address))
    vehicles: Dict[str, Vehicle] = UserProperty(SchemaDict(Vehicle))
Ejemplo n.º 8
0
class Address(UserObject):
    first_line: str = UserProperty(str)
    second_line: str = UserProperty(str)
    city: str = UserProperty(str)
    postal_code: str = UserProperty(int)
Ejemplo n.º 9
0
class Address(UserObject):
    zip_code: int = UserProperty(int, pattern=r"^[0-9]{5}$")
Ejemplo n.º 10
0
class Address(UserObject):
    first_line: str = UserProperty(str, pattern=r"^(\d)+.*$")
    second_line: str = UserProperty(str, optional=True)
    city: str = UserProperty(str)
    postal_code: str = UserProperty(int)
class Person(UserObject):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str, default="", optional=False)
Ejemplo n.º 12
0
class Person(UserObject):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str,
                                  default="",
                                  default_function=lambda x: x.first_name)