缩小多处理管理器代理的类型

问题描述 投票:0回答:1

multiprocessing.managers.SyncManager.list
返回
ListProxy[Any]
,但我没有看到缩小
Any
的方法?

作为解决方法,我可以:

int_list = cast("ListProxy[int]", m.list())

并且

int_list
ListProxy[int]

另请注意,类型上需要

"
,以避免:

TypeError: type 'ListProxy' is not subscriptable`:

有更好的方法吗?

python generics multiprocessing typing
1个回答
0
投票

使用 typeshed 定义的稍微好一点的版本

results = m.list(cast(list[int], []))
© www.soinside.com 2019 - 2024. All rights reserved.