【发布时间】:2018-05-28 09:11:26
【问题描述】:
我有这个非常简单的功能:
import datetime
def create_url(check_in: datetime.date) -> str:
"""take date such as '2018-06-05' and transform to format '06%2F05%2F2018'"""
_check_in = check_in.strftime("%Y-%m-%d")
_check_in = _check_in.split("-")
_check_in = _check_in[1] + "%2F" + _check_in[2] + "%2F" + _check_in[0]
return f"https://www.website.com/?arrival={_check_in}"
mypy 抛出以下错误:
error:Incompatible types in assignment (expression has type "List[str]", variable has type "str") 第 6 行 _check_in = _check_in.split("-")。
我尝试在第 6 行重命名 _check_in,但这并没有什么区别。此功能工作正常。
这是预期的行为吗?如何修复错误。
谢谢!
【问题讨论】:
-
顺便说一句,您的代码缺少一个额外的
",这会导致您的代码块像文档字符串一样格式化 -
谢谢 - 现在已更正。
标签: python python-3.x mypy