MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / formatannotation

Function formatannotation

tools/python-3.11.9-amd64/Lib/inspect.py:1437–1449  ·  view source on GitHub ↗
(annotation, base_module=None)

Source from the content-addressed store, hash-verified

1435 return ArgInfo(args, varargs, varkw, frame.f_locals)
1436
1437def formatannotation(annotation, base_module=None):
1438 if getattr(annotation, '__module__', None) == 'typing':
1439 def repl(match):
1440 text = match.group()
1441 return text.removeprefix('typing.')
1442 return re.sub(r'[\w\.]+', repl, repr(annotation))
1443 if isinstance(annotation, types.GenericAlias):
1444 return str(annotation)
1445 if isinstance(annotation, type):
1446 if annotation.__module__ in ('builtins', base_module):
1447 return annotation.__qualname__
1448 return annotation.__module__+'.'+annotation.__qualname__
1449 return repr(annotation)
1450
1451def formatannotationrelativeto(object):
1452 module = getattr(object, '__module__', None)

Callers 3

_formatannotationFunction · 0.85
__str__Method · 0.85
__str__Method · 0.85

Calls 2

strFunction · 0.85
subMethod · 0.45

Tested by

no test coverage detected