小编Tyf*_*ngr的帖子

从 Python 中的协议继承

在 Python 中继承 Protocols 有什么好处吗?

例如。

class SampleProtocol(Protocol):
    def do_something(self) -> int:
      ...
    
class Sample(SampleProtocol):
    def do_something(self) -> int:
        return 10
Run Code Online (Sandbox Code Playgroud)

或者应该Sample只是一个实现协议而不显式继承它的类?

python mypy

11
推荐指数
2
解决办法
2292
查看次数

标签 统计

mypy ×1

python ×1