class Pet(UserObject, RegistersSubclasses, ABC): pet_type: str = UserProperty(str) name: str = UserProperty(str) @abstractmethod def speak(self): pass
class Vehicle(UserObject): color: str = UserProperty(str) description: str = UserProperty(str) @property def license(self): return key(self)
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)
class Cat(Pet): pet_type: str = UserProperty(SchemaConst("cat")) def speak(self): return f"{self.name} says Miaow!"
class Person(UserObject): first_name: str = UserProperty(str) last_name: str = UserProperty(str) pets: List[Pet] = UserProperty(SchemaArray(Pet))
class Greyhound(Dog): pet_type: str = UserProperty(SchemaConst("greyhound")) def speak(self): return f"{self.name}, the greyhound, says Woof!"
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))
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}$")
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)