当我注意到 Pylancenumpy.pi
作为 NoseTester 的成员numpy.testing
或类型时,我正在向函数调用添加类型提示。
即使我进入type(np.pi) == float
了 python 命令行,这个示例代码:
import numpy as np
def foo(val: float):
print(val)
foo(np.pi)
给出以下错误消息foo(np.pi)
pi: Module("numpy.testing") | Type[NoseTester]
Argument of type "Module("numpy.testing") | Type[NoseTester]" cannot be assigned to parameter "val" of type "float" in function "foo"
Type "Module("numpy.testing") | Type[NoseTester]" cannot be assigned to type "float"
Type "Module("numpy.testing")" cannot be assigned to type "float"
"Type[type]" is incompatible with "Type[float]"PylancereportGeneralTypeIssues
对于以下内容,我收到了相同的错误消息(对于 float 以外的类型):numpy.pi
, numpy.e
, numpy.floor
, numpy.ceil
, numpy.sin
, numpy.cos
, numpy.tan
, numpy.sqrt
, numpy.exp
.
但是,这些浮点数/函数不会导致问题:numpy.Inf
, numpy.Nan
, numpy.round
, numpy.real
, numpy.imag
, numpy.random.rand
.
我在跑:
- 麻木:1.19.5
- 皮兰斯:2021.5.3
有谁知道这是为什么和/或如何解决这个问题?
编辑 1:这似乎更像是一个 Pylance 问题,所以我创建了microsoft/pylance-release#1340