【问题标题】:ValueProxy[int] throws error: 'type' object is not subscriptableValueProxy[int] 抛出错误:“类型”对象不可下标
【发布时间】:2022-01-05 20:01:14
【问题描述】:

我有以下代码:

from multiprocessing.managers import ValueProxy

def test(value: ValueProxy[int]):
    print("foo")

test(None)

它会抛出这个错误:

Traceback (most recent call last):
  File ".../test.py", line 4, in <module>
    def test(value: ValueProxy[int]):
TypeError: 'type' object is not subscriptable

如何键入提示ValueProxy[int]

【问题讨论】:

    标签: python types python-multiprocessing type-hinting


    【解决方案1】:

    在 Python 3.9 (PEP 585) 中为 multiprocessing.managers 模块以及其他标准库模块添加了类型提示泛型(= 编写 ValueProxy[int] 而不仅仅是 ValueProxy)。

    见:

    您使用的 Python 版本似乎早于 3.9。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2018-02-27
      • 2012-04-04
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 2020-12-10
      相关资源
      最近更新 更多