def annotations(memb):
"""Decorator applicable to functions, methods, properties,
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_annotations_decorator to apply this on all modules.
Methods with type comment will have type hints parsed from that
string and get them attached as __annotations__ attribute.
Methods with either a type comment or ordinary type annotations in
a stubfile will get that information attached as __annotations__
attribute (also a relevant use case in Python 3).
Behavior in case of collision with previously (manually)
attached __annotations__ can be controlled using the flags
pytypes.annotations_override_typestring and pytypes.annotations_from_typestring.
"""
if _check_as_func(memb):
return annotations_func(memb)
if isclass(memb):
return annotations_class(memb)
if ismodule(memb):
return annotations_module(memb)
if memb in sys.modules or memb in pytypes.typechecker._pending_modules:
return annotations_module(memb)
return memb
评论列表
文章目录