Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

python - How to run a static method of a generic type?

class A:
    @staticmethod
    def work():
        print("works")

T = TypeVar('T', bound=A)
class B(Generic[T]):
    @staticmethod
    def execute():
        T.work() # this doesn't work
        # A.work() # but this would work

B[A].execute()

T.work() doesn't work because T has no function work. Why doesn't it have? How can I change T to type from which I could run function work?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...