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)
| 1084 | |
| 1085 | |
| 1086 | def 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 | |
| 1106 | def annotations_to_string(annotations): |
searching dependent graphs…