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
评论列表
文章目录