Beispiel #1
0
class Pet(UserObject, RegistersSubclasses, ABC):
    pet_type: str = UserProperty(str)
    name: str = UserProperty(str)

    @abstractmethod
    def speak(self):
        pass
Beispiel #2
0
class Vehicle(UserObject):
    color: str = UserProperty(str)
    description: str = UserProperty(str)

    @property
    def license(self):
        return key(self)
Beispiel #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)
Beispiel #4
0
class Cat(Pet):
    pet_type: str = UserProperty(SchemaConst("cat"))

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

    def speak(self):
        return f"{self.name}, the greyhound, says Woof!"
Beispiel #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))
Beispiel #8
0
class Address(UserObject):
    first_line: str = UserProperty(str)
    second_line: str = UserProperty(str)
    city: str = UserProperty(str)
    postal_code: str = UserProperty(int)
class Address(UserObject):
    zip_code: int = UserProperty(int, pattern=r"^[0-9]{5}$")
Beispiel #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)
class Person(UserObject):
    first_name: str = UserProperty(str)
    last_name: str = UserProperty(str,
                                  default="",
                                  default_function=lambda x: x.first_name)