Pylance 将 numpy.pi 错误地输入为 "Module("numpy.testing") | Type[NoseTester]"

Pylance incorrectly typing numpy.pi as "Module("numpy.testing") | Type[NoseTester]"

当我注意到 Pylance 正在键入 numpy.pi 作为 numpy.testing 的成员或属于 NoseTester 类型时,我正在向函数调用添加类型提示。

即使我在 python 命令行中得到 type(np.pi) == float,这个示例代码:

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.pinumpy.enumpy.floornumpy.ceilnumpy.sin, numpy.cos, numpy.tan, numpy.sqrt, numpy.exp.

但是,这些 floats/functions 不会导致问题:numpy.Infnumpy.Nannumpy.roundnumpy.realnumpy.imag , numpy.random.rand.

我是 运行:

有谁知道这是为什么 and/or 如何解决这个问题?

编辑 1:这似乎更像是 Pylance 的问题,所以我创建了 microsoft/pylance-release#1340

我觉得真的很蠢——我只需要将 Numpy 更新到 1.20 版本。正如所指出的 on GitHub by Jake Bailey,Numpy 在 1.20 之前不包含输入信息。