MCPcopy Index your code
hub / github.com/python/cpython / formatannotation

Function formatannotation

Lib/inspect.py:1363–1379  ·  view source on GitHub ↗
(annotation, base_module=None, *, quote_annotation_strings=True)

Source from the content-addressed store, hash-verified

1361 return ArgInfo(args, varargs, varkw, frame.f_locals)
1362
1363def formatannotation(annotation, base_module=None, *, quote_annotation_strings=True):
1364 if not quote_annotation_strings and isinstance(annotation, str):
1365 return annotation
1366 if getattr(annotation, '__module__', None) == 'typing':
1367 def repl(match):
1368 text = match.group()
1369 return text.removeprefix('typing.')
1370 return re.sub(r'[\w\.]+', repl, repr(annotation))
1371 if isinstance(annotation, types.GenericAlias):
1372 return str(annotation)
1373 if isinstance(annotation, type):
1374 if annotation.__module__ in ('builtins', base_module):
1375 return annotation.__qualname__
1376 return annotation.__module__+'.'+annotation.__qualname__
1377 if isinstance(annotation, ForwardRef):
1378 return annotation.__forward_arg__
1379 return repr(annotation)
1380
1381def formatannotationrelativeto(object):
1382 module = getattr(object, '__module__', None)

Callers 3

_formatannotationFunction · 0.85
_formatMethod · 0.85
formatMethod · 0.85

Calls 2

strFunction · 0.85
subMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…