【发布时间】:2021-09-05 01:15:12
【问题描述】:
我有以下内容,我预计会引发错误:
# check.py
import pandas as pd
def f(s : str) -> None:
print(s)
def main() -> None:
f(s = pd.Series([1,2]))
if __name__ == "__main__":
main()
但是,mypy check.py 返回Success: no issues found in 1 source file。
应该如何为 pandas 系列提供类型提示?
def _constructor(self) -> type[Series]:
return Series
type[Series],我不确定我们是否应该这样输入提示系列?
编辑
将代码更新为:
# check.py
import pandas as pd
def f(s : str) -> None:
print(s)
def g(s : str) -> None:
print(s)
def main() -> None:
f(s = pd.Series([1,2]))
g(s = 12.9)
if __name__ == "__main__":
main()
给出输出:
check.py:12: error: Argument "s" to "g" has incompatible type "float"; expected "str" [arg-type]
Found 1 error in 1 file (checked 1 source file)
【问题讨论】:
标签: python pandas type-hinting mypy typing