【发布时间】:2021-12-02 05:36:16
【问题描述】:
具有以下功能:
from typing import ClassVar
def overrode_make_stub(cls: ClassVar["Emailer"]) -> bool:
return not (getattr(cls.make_stub, "_not_overridden", False))
我在 Visual Studio Code 中从 Pylance 收到此错误:
在此上下文中不允许使用“ClassVar”
我正在使用 Python3.9 和 Pylance v2021.10.0。
在这个例子中,Email 类有一个“make_stub”函数,它的_not_overriden 属性设置为True。当我检查模块以查找该类的子类时,我可以使用它来过滤仅覆盖“make_sub”函数的模块。
我找不到有关此错误的任何文档。有谁知道为什么会出现?
【问题讨论】:
标签: python type-hinting python-typing pylance