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

Function type_repr

Lib/annotationlib.py:1086–1103  ·  view source on GitHub ↗

Convert a Python value to a format suitable for use with the STRING format. This is intended as a helper for tools that support the STRING format but do not have access to the code that originally produced the annotations. It uses repr() for most objects.

(value)

Source from the content-addressed store, hash-verified

1084
1085
1086def type_repr(value):
1087 """Convert a Python value to a format suitable for use with the STRING format.
1088
1089 This is intended as a helper for tools that support the STRING format but do
1090 not have access to the code that originally produced the annotations. It uses
1091 repr() for most objects.
1092
1093 """
1094 if isinstance(value, (type, types.FunctionType, types.BuiltinFunctionType)):
1095 if value.__module__ == "builtins":
1096 return value.__qualname__
1097 return f"{value.__module__}.{value.__qualname__}"
1098 elif isinstance(value, _Template):
1099 tree = _template_to_ast(value)
1100 return ast.unparse(tree)
1101 if value is ...:
1102 return "..."
1103 return repr(value)
1104
1105
1106def annotations_to_string(annotations):

Callers 3

__repr__Method · 0.90
test_type_reprMethod · 0.90
annotations_to_stringFunction · 0.85

Calls 1

_template_to_astFunction · 0.85

Tested by 1

test_type_reprMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…