重复使用不同类方法的方法签名
我想重复使用method1
classa
clasta on Method1_1 classB
以某种方式像接口一样。 什么是一种通用方法来指示/强制执行Method1_1
具有与Method1_1
的签名相同的签名?
class ClassA():
def method1(self, a:int, b:str, c:list[str]):
pass
class ClassB():
class_a: ClassA
def method1_1(self, a:int, b:str, c:list[str]):
self.class_a(a,b,c)
I would like to reuse the method1
signature of ClassA
on method1_1 ClassB
somehow like an interface.
What is a general approach to indicate/enforce that method1_1
has the same signature as method1_1
?
class ClassA():
def method1(self, a:int, b:str, c:list[str]):
pass
class ClassB():
class_a: ClassA
def method1_1(self, a:int, b:str, c:list[str]):
self.class_a(a,b,c)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以介绍抽象基类和抽象基类的装饰工:
You could introduces an abstract base class and a decorator for the abstract base class: