我在Neovim v0.7.0中使用了pright-langserver。它运行良好,只是我不知道如何在以下情况下正确注解类型。
import pandas as pd
df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},index=['dog', 'hawk'])
for row in df.itertuples():
print(row.num_legs) # ■ Cannot access member "num_legs" for type "tuple[Any, ...]" Member "num_legs" is unknown
如您所见,我添加了一条注解,显示了pyright报告的错误:Cannot access member "num_legs" for type "tuple[Any, ...]" Member "num_legs" is unknown
这段代码是有效的,因为它打印了4,然后打印了2,正如我所期望的那样。我如何满足类型检查呢?
1条答案
按热度按时间shyt4zoc1#
我还没有找到解决类型问题的方法(Pandas只是将类型作为泛型元组),但是至少有两种方法可以抑制错误报告。
1.告诉Pyrright到ignore the error:
1.将类型cast()为Any以关闭对象的类型冲突