相关疑难解决方法(0)

Callable 是无效的基类?

有人可以解释为什么从 unparameterized 和 parameterized 继承Callable

from typing import Callable
from typing import NoReturn
from typing import TypeVar


T = TypeVar('T', str, int)
C = Callable[[T], NoReturn]


class Foo(Callable):

    def __call__(self, t: T):
        pass


class Bar(C):

    def __call__(self, t: T):
        pass
Run Code Online (Sandbox Code Playgroud)

传递给mypy时提出了两个错误FooBar

tmp.py:13: error: Invalid base class
tmp.py:19: error: Invalid base class
Run Code Online (Sandbox Code Playgroud)

python type-hinting mypy

6
推荐指数
1
解决办法
1014
查看次数

标签 统计

mypy ×1

python ×1

type-hinting ×1