我正在使用 pyre-checking 进行静态类型测试,我想忽略项目中的特定错误。
例如: 未定义的属性 [16]:模块google.protobuf.struct_pb2没有属性_STRUCT。
假设如果我想从我的项目中忽略这个错误,我该怎么做?
如何正确编写返回类型被装饰器修改的函数的类型?
简单的例子:
def example_decorator(fn):
def wrapper(data):
res = fn(data)
return ', '.join(res)
return wrapper
@example_decorator
def func(data: list): # -> ???? str ? list ?
new_data = data
new_data.append('XYZ')
return new_data
# When we type func -> list
def test() -> str:
result = func(['ABC', 'EFG'])
print(type(result)) # <class 'str'>
return result # Incompatible return type [7]: Expected str but got list.
test()
Run Code Online (Sandbox Code Playgroud) a.py:
import numpy
Run Code Online (Sandbox Code Playgroud)
柴堆
a.py:1:0 Undefined import [21]: Could not find a module corresponding to import `numpy`.
Run Code Online (Sandbox Code Playgroud)
虽然我肯定已经安装了 numpy。
环境:Ubuntu、python 3.7.1、pyre 0.0.22、numpy 1.16.2