MCPcopy Index your code
hub / github.com/RustPython/RustPython / formatannotation

Function formatannotation

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

Source from the content-addressed store, hash-verified

1337 return ArgInfo(args, varargs, varkw, frame.f_locals)
1338
1339def formatannotation(annotation, base_module=None, *, quote_annotation_strings=True):
1340 if not quote_annotation_strings and isinstance(annotation, str):
1341 return annotation
1342 if getattr(annotation, '__module__', None) == 'typing':
1343 def repl(match):
1344 text = match.group()
1345 return text.removeprefix('typing.')
1346 return re.sub(r'[\w\.]+', repl, repr(annotation))
1347 if isinstance(annotation, types.GenericAlias):
1348 return str(annotation)
1349 if isinstance(annotation, type):
1350 if annotation.__module__ in ('builtins', base_module):
1351 return annotation.__qualname__
1352 return annotation.__module__+'.'+annotation.__qualname__
1353 if isinstance(annotation, ForwardRef):
1354 return annotation.__forward_arg__
1355 return repr(annotation)
1356
1357def formatannotationrelativeto(object):
1358 module = getattr(object, '__module__', None)

Callers 3

_formatannotationFunction · 0.85
_formatMethod · 0.85
formatMethod · 0.85

Calls 5

isinstanceFunction · 0.85
getattrFunction · 0.85
reprFunction · 0.85
strFunction · 0.85
subMethod · 0.45

Tested by

no test coverage detected