Dor*_*ori 6 python callable mypy
Mypy 似乎无法理解属性不是类的可调用方法:
from abc import abstractmethod
from typing import Type
class A:
pass
class B:
@abstractmethod
@property
@classmethod
def other_type(cls) -> Type[A]:
pass
@classmethod
def __init_subclass__(cls, **kwargs):
assert issubclass(cls.other_type, A)
Run Code Online (Sandbox Code Playgroud)
在上面的示例上运行 mypy 会导致以下错误:
error: Argument 1 to "issubclass" has incompatible type "Callable[[], Type[A]]"; expected "type" [arg-type]
Run Code Online (Sandbox Code Playgroud)
如果没有 ,我如何强制执行正确的类型# type: ignore[arg-type]?我正在使用 mypy 版本 0.782 和 python 3.7
(注意:我正在使用该--check-untyped-defs标志运行 mypy,因此 mypy 应该扫描该__init_subclass__方法)。
| 归档时间: |
|
| 查看次数: |
974 次 |
| 最近记录: |