擅长:python、mysql、java
<p>参数子类型与返回子类型的方向相反</p>
<ul>
<li>返回值从被调用方分配给调用方</李>
<li>参数值从调用者分配给被调用者</李>
</ul>
<p>赋值应该比变量的预期类型更具体。
例如:</p>
<pre class="lang-py prettyprint-override"><code>data: Data = SpecificData() # okay
data: SpecificData = Data() # not okay
</code></pre>
<p>所以你应该:</p>
<pre class="lang-py prettyprint-override"><code>from typing import Callable, Any
class Data:
pass
class SpecificData(Data):
pass
class Event:
pass
class SpecificEvent(Event):
pass
def detect_specific_event(data: Data, other_info: str) -> SpecificEvent:
return SpecificEvent()
def run_detection(callback: Callable[[SpecificData, Any], Event]) -> None:
return
run_detection(detect_specific_event)
</code></pre>