键入提示:将类型指定为bool或callable

时间:2017-12-07 08:50:43

标签: python python-3.x type-hinting

给定一个基类,如(伪编码):

class A():

    def has_permission(self, *args, **kwargs):
        action = getattr(self, 'can_view')
        if callable(action):
            return action(*args, **kwargs)
        return action

    def can_view(self, *args, **kwargs):
        return False

和子类如:

class B(A):

    can_view = True

如何输入提示?

Mypy引发了这个错误:

Incompatible types in assignment (expression has type "bool", base class "A" defined the type as "Callable[]")

我真的不知道该怎么做。

0 个答案:

没有答案
相关问题