MCPcopy
hub / github.com/rocky/python-uncompyle6 / n_build_list_unpack

Function n_build_list_unpack

uncompyle6/semantics/customize37.py:249–309  ·  view source on GitHub ↗

prettyprint a list or tuple

(node)

Source from the content-addressed store, hash-verified

247 self.n_attribute37 = n_attribute37
248
249 def n_build_list_unpack(node):
250 """
251 prettyprint a list or tuple
252 """
253 p = self.prec
254 self.prec = 100
255 lastnode = node.pop()
256 lastnodetype = lastnode.kind
257
258 # If this build list is inside a CALL_FUNCTION_VAR,
259 # then the first * has already been printed.
260 # Until I have a better way to check for CALL_FUNCTION_VAR,
261 # will assume that if the text ends in *.
262 last_was_star = self.f.getvalue().endswith("*")
263
264 if lastnodetype.startswith("BUILD_LIST"):
265 self.write("[")
266 endchar = "]"
267 else:
268 endchar = ""
269
270 flat_elems = flatten_list(node)
271
272 self.indent_more(INDENT_PER_LEVEL)
273 sep = ""
274 for elem in flat_elems:
275 if elem in ("ROT_THREE", "EXTENDED_ARG"):
276 continue
277 assert elem == "expr"
278 line_number = self.line_number
279 use_star = True
280 value = self.traverse(elem)
281 if value.startswith("("):
282 assert value.endswith(")")
283 use_star = False
284 value = value[1:-1].rstrip(
285 " "
286 ) # Remove starting '(' and trailing ')' and additional spaces
287 if value == "":
288 pass
289 else:
290 if value.endswith(","): # if args has only one item
291 value = value[:-1]
292 if line_number != self.line_number:
293 sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
294 else:
295 if sep != "":
296 sep += " "
297 if not last_was_star and use_star:
298 sep += "*"
299 pass
300 else:
301 last_was_star = False
302 self.write(sep, value)
303 sep = ","
304 self.write(endchar)
305 self.indent_less(INDENT_PER_LEVEL)
306

Callers

nothing calls this directly

Calls 5

flatten_listFunction · 0.90
indent_moreMethod · 0.80
indent_lessMethod · 0.80
writeMethod · 0.45
traverseMethod · 0.45

Tested by

no test coverage detected