HW3 complete #2
@ -15,21 +15,31 @@ class TurtleDevice(SynchronyDevice):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
def open(self):
|
def open(self) -> None:
|
||||||
self.turtle = Turtle()
|
self.turtle = Turtle()
|
||||||
|
|
||||||
def close(self):
|
def close(self)-> None:
|
||||||
del self.turtle
|
del self.turtle
|
||||||
|
self.close()
|
||||||
|
|
||||||
def execute(self, action_name: str, *args, **kwargs):
|
def execute(self, action_name: str, *args, **kwargs) -> None:
|
||||||
pass
|
actions = self.action_descriptors
|
||||||
|
for action in actions:
|
||||||
|
if action.name == action_name:
|
||||||
|
# NOTE: судя по заданию, должен быть такой чекер, но почему-то у меня inspect плохо спарсил типы
|
||||||
|
# везде empty_time, хотя судя по доке в модуле typos проставлены
|
||||||
|
# for argument in kwargs:
|
||||||
|
# action_tmp_argument_type = action.arguments[argument]
|
||||||
|
# given_method_tmp_argument = type(kwargs[argument])
|
||||||
|
# assert (
|
||||||
|
# action_tmp_argument_type == given_method_tmp_argument
|
||||||
|
# ), f"Переданный аргумент должен быть типа {action_tmp_argument_type}, вы передали {given_method_tmp_argument}"
|
||||||
|
getattr(self.turtle, action_name)(*args, **kwargs)
|
||||||
|
return
|
||||||
|
raise NoSuchAction
|
||||||
|
|
||||||
def read(self, trait_name: str) -> Any:
|
def read(self, trait_name: str) -> Any:
|
||||||
traits = self.trait_descriptors
|
return Turtle().__getattribute__(trait_name)
|
||||||
for trait in traits:
|
|
||||||
if trait.name == trait_name:
|
|
||||||
return self.turtle.__getattribute__(trait_name)
|
|
||||||
raise NoSuchTrait
|
|
||||||
|
|
||||||
def write(self, trait_name: str, value: Any) -> bool:
|
def write(self, trait_name: str, value: Any) -> bool:
|
||||||
traits = self.trait_descriptors
|
traits = self.trait_descriptors
|
||||||
@ -43,11 +53,17 @@ class TurtleDevice(SynchronyDevice):
|
|||||||
return True
|
return True
|
||||||
raise NoSuchTrait
|
raise NoSuchTrait
|
||||||
|
|
||||||
def invalidate(self, trait_name: str):
|
def invalidate(self, trait_name: str) -> None:
|
||||||
pass
|
# NOTE: если я правильно понял, что должен делать метод
|
||||||
|
self.write(trait_name=trait_name, value=Turtle().__getattribute__(trait_name))
|
||||||
|
return
|
||||||
|
|
||||||
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
||||||
pass
|
traits = self.trait_descriptors
|
||||||
|
for trait in traits:
|
||||||
|
if trait.name == trait_name:
|
||||||
|
return self.turtle.__getattribute__(trait_name)
|
||||||
|
raise NoSuchTrait
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
||||||
|
Loading…
Reference in New Issue
Block a user