小编Jam*_*rts的帖子

枚举导致 mypy 类型不兼容错误

下面的代码:

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

python typing enumerate mypy

5
推荐指数
1
解决办法
2072
查看次数

java 如何检查日期是否在今天之后

我试图检查用户输入的日期是否在今天之后。这是我的代码:

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 为空。有什么想法吗?谢谢

java parsing date simpledateformat

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

date ×1

enumerate ×1

java ×1

mypy ×1

parsing ×1

python ×1

simpledateformat ×1

typing ×1