MCPcopy Index your code
hub / github.com/python/mypy / object_annotation

Method object_annotation

mypyc/codegen/emit.py:239–257  ·  view source on GitHub ↗

Build a C comment with an object's string representation. If the comment exceeds the line length limit, it's wrapped into a multiline string (with the extra lines indented to be aligned with the first line's comment). If it contains illegal characters, an empty stri

(self, obj: object, line: str)

Source from the content-addressed store, hash-verified

237 return ATTR_PREFIX + name
238
239 def object_annotation(self, obj: object, line: str) -> str:
240 """Build a C comment with an object's string representation.
241
242 If the comment exceeds the line length limit, it's wrapped into a
243 multiline string (with the extra lines indented to be aligned with
244 the first line's comment).
245
246 If it contains illegal characters, an empty string is returned."""
247 line_width = self._indent + len(line)
248 formatted = pprint.pformat(obj, compact=True, width=max(90 - line_width, 20))
249 if any(x in formatted for x in ("/*", "*/", "\0")):
250 return ""
251
252 if "\n" in formatted:
253 first_line, rest = formatted.split("\n", maxsplit=1)
254 comment_continued = textwrap.indent(rest, (line_width + 3) * " ")
255 return f" /* {first_line}\n{comment_continued} */"
256 else:
257 return f" /* {formatted} */"
258
259 def emit_line(self, line: str = "", *, ann: object = None) -> None:
260 if line.startswith("}"):

Callers 2

emit_lineMethod · 0.95

Calls 5

lenFunction · 0.85
maxFunction · 0.85
anyFunction · 0.85
splitMethod · 0.80
indentMethod · 0.45

Tested by 1