typechecker.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pytypes 作者: Stewori 项目源码 文件源码
def auto_override(memb):
    """Decorator applicable to methods, classes or modules (by explicit call).
    If applied on a module, memb must be a module or a module name contained in sys.modules.
    See pytypes.set_global_auto_override_decorator to apply this on all modules.
    Works like override decorator on type annotated methods that actually have a type
    annotated parent method. Has no effect on methods that do not override anything.
    In contrast to plain override decorator, auto_override can be applied easily on
    every method in a class or module.
    In contrast to explicit override decorator, auto_override is not suitable to detect
    typos in spelling of a child method's name. It is only useful to assert compatibility
    of type information (note that return type is contravariant).
    Use pytypes.check_override_at_runtime and pytypes.check_override_at_class_definition_time
    to control whether checks happen at class definition time or at "actual runtime".
    """
    if type_util._check_as_func(memb):
        return override(memb, True)
    if isclass(memb):
        return auto_override_class(memb)
    if ismodule(memb):
        return auto_override_module(memb, True)
    if memb in sys.modules or memb in _pending_modules:
        return auto_override_module(memb, True)
    return memb
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号