HW3_upgrade

This commit is contained in:
MarieMih 2023-11-19 19:46:40 +03:00
parent 1fbdae751c
commit 2a3032d4e7

View File

@ -2,34 +2,45 @@ from turtle import Turtle
from typing import Any from typing import Any
from equipment.device import SynchronyDevice from equipment.device import SynchronyDevice
import inspect import inspect
import types
class TurtleDevice(SynchronyDevice): class TurtleDevice(SynchronyDevice):
def open(self): def open(self):
super().open() super().open()
return Turtle() return Turtle()
@staticmethod
def close (self): def close (exam):
super().close() super().close()
del(self) del exam
@property @property
def trait_descriptors(self): def trait_descriptors(self):
print("This is all class attributes: ", l) l = list()
for i in dir(Turtle): for i in inspect.getmembers(TurtleDevice):
if not i.startswith("__") and inspect.ismethod(Turtle.i)==False: if not (i[0].startswith("__") or i[0].startswith("_")) and not inspect.isfunction(i[1]):
print(i, '\n') l.append(i[0])
return l
@property @property
def action_descriptors(self): def action_descriptors(self):
print("This is all class methods: \n") l = list()
for i in dir(Turtle): #print(inspect.getmembers(TurtleDevice))
if not i.startswith("__") and inspect.ismethod(Turtle.i)==True: #for i in dir(TurtleDevice):
sig = inspect.signature(Turtle.i) # # print(type(getattr(TurtleDevice(), i))=='method')
print(i, str(sig), '\n') # # if not i.startswith("__") and type(getattr(TurtleDevice(), i)) == types.MethodType:
# if not i.startswith("__") and inspect.isroutine(inspect.getattr_static(TurtleDevice, i)):
# sig = inspect.signature(getattr(TurtleDevice, i))
# l.append(i + " " + str(sig))
#return l
for i in inspect.getmembers(TurtleDevice):
# print(type(getattr(TurtleDevice, i)))
# print(type(getattr(TurtleDevice(), i))=='method')
if not (i[0].startswith("__") or i[0].startswith("_")) and inspect.isfunction(i[1]):
sig = inspect.signature(getattr(TurtleDevice, i[0]))
l.append(i[0]+str(sig))
return l
def execute(self, action_name: str, *args, **kwargs): def execute(self, action_name: str, *args, **kwargs):
"""Execute action `action_name`, using `args` and `kwargs` as action argument.""" """Execute action `action_name`, using `args` and `kwargs` as action argument."""
pass pass
@ -45,10 +56,7 @@ class TurtleDevice(SynchronyDevice):
def invalidate(self, trait_name: str): def invalidate(self, trait_name: str):
"""Invalidate logical state of trait `trait_name`""" """Invalidate logical state of trait `trait_name`"""
pass pass
#print(TurtleDevice.action_descriptors())
#t = TurtleDevice()
#print(t.trait_descriptors)