下面的代码:
from typing import Union
def process(actions: Union[list[str], list[int]]) -> None:
for pos, action in enumerate(actions):
act(action)
def act(action: Union[str, int]) -> None:
print(action)
Run Code Online (Sandbox Code Playgroud)
生成 mypy 错误: Argument 1 to "act" has incompatible type "object"; expected "Union[str, int]"
但是,当删除枚举函数时,输入就可以了:
from typing import Union
def process(actions: Union[list[str], list[int]]) -> None:
for action in actions:
act(action)
def act(action: Union[str, int]) -> None:
print(action)
Run Code Online (Sandbox Code Playgroud)
有谁知道枚举函数正在做什么来影响类型?这是 python 3.9 和 mypy 0.921
我试图检查用户输入的日期是否在今天之后。这是我的代码:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date enteredDate = sdf.parse(date);
Date currentDate = new Date();
if(enteredDate.after(currentDate)){
Run Code Online (Sandbox Code Playgroud)
Date 是一个变量,用户日期的格式为“2016/04/26”。经过一些调试后,我发现 EnteredDate 和 currentDate 为空。有什么想法吗?谢谢