You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from typing import List
from abc import ABC, abstractmethod
from wysdom import UserObject, UserProperty, SchemaArray, SchemaConst
from wysdom.mixins import RegistersSubclasses
class Pet(UserObject, RegistersSubclasses, ABC):
pet_type: str = UserProperty(str)
name: str = UserProperty(str)
@abstractmethod
def speak(self):
pass
class Person(UserObject):
first_name: str = UserProperty(str)
last_name: str = UserProperty(str)
pets: List[Pet] = UserProperty(SchemaArray(Pet))
class Dog(Pet):
def speak(self):
return f"{self.name} says Woof!"
class Greyhound(Dog):
pet_type: str = UserProperty(SchemaConst("greyhound"))
def speak(self):
return f"{self.name}, the greyhound, says Woof!"
class Cat(Pet):
pet_type: str = UserProperty(SchemaConst("cat"))
def speak(self):
return f"{self.name} says Miaow!"
example_dict_input = {
"first_name": "Marge",
"last_name": "Simpson",
"pets": [
{
"pet_type": "greyhound",
"name": "Santa's Little Helper",
},
{
"pet_type": "cat",
"name": "Snowball II",
}
]
}
example = Person(example_dict_input)
Results in:
Traceback (most recent call last):
File "late_subclass.py", line 57, in <module>
example = Person(example_dict_input)
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/user_objects/UserObject.py", line 136, in __init__
super().__init__({**(value or {}), **kwargs}, json_dom_info)
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMObject.py", line 44, in __init__
self[key] = value
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMObject.py", line 73, in __setitem__
element_key=key
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/object_schema/SchemaArray.py", line 36, in __call__
item_type=self.items
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMList.py", line 50, in __init__
self[:] = value
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMList.py", line 75, in __setitem__
self.__json_element_data__[i] = (self._new_child_item(x) for x in o)
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMList.py", line 75, in <genexpr>
self.__json_element_data__[i] = (self._new_child_item(x) for x in o)
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/dom/DOMList.py", line 82, in _new_child_item
parent=self
File "/mnt/c/Users/U568912/Gitroot/wysdom/wysdom/object_schema/SchemaObject.py", line 49, in __call__
return self.object_type(value, dom_info)
TypeError: Can't instantiate abstract class Pet with abstract methods speak
The text was updated successfully, but these errors were encountered:
Results in:
The text was updated successfully, but these errors were encountered: