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

Function type_repr

Lib/annotationlib.py:1073–1090  ·  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

1071
1072
1073def type_repr(value):
1074 """Convert a Python value to a format suitable for use with the STRING format.
1075
1076 This is intended as a helper for tools that support the STRING format but do
1077 not have access to the code that originally produced the annotations. It uses
1078 repr() for most objects.
1079
1080 """
1081 if isinstance(value, (type, types.FunctionType, types.BuiltinFunctionType)):
1082 if value.__module__ == "builtins":
1083 return value.__qualname__
1084 return f"{value.__module__}.{value.__qualname__}"
1085 elif isinstance(value, _Template):
1086 tree = _template_to_ast(value)
1087 return ast.unparse(tree)
1088 if value is ...:
1089 return "..."
1090 return repr(value)
1091
1092
1093def annotations_to_string(annotations):

Callers 3

__repr__Method · 0.90
test_type_reprMethod · 0.90
annotations_to_stringFunction · 0.85

Calls 3

isinstanceFunction · 0.85
_template_to_astFunction · 0.85
reprFunction · 0.85

Tested by 1

test_type_reprMethod · 0.72