【发布时间】:2019-06-27 22:55:22
【问题描述】:
这曾经适用于旧版本(0.6xx?)的 mypy:
import pathlib
import shutil
from typing import Union
def f(x: Union[str, pathlib.Path]):
shutil.copyfile("bla", x)
但不是在它抱怨的 mypy 0.710 中:
error: Value of type variable "_AnyPath" of "copyfile" cannot be "Union[str, Path]"
应该如何解决?
【问题讨论】:
-
我觉得这是 mypy 中的一个错误/缺失功能——基本上,您的错误可以归结为 mypy 未按预期处理 this program。我可能会尝试在mypy issue tracker 上报告这个?