MCPcopy Index your code
hub / github.com/rocky/python-uncompyle6 / n_list_unpack

Function n_list_unpack

uncompyle6/semantics/customize35.py:258–345  ·  view source on GitHub ↗

prettyprint an unpacked list or tuple

(node)

Source from the content-addressed store, hash-verified

256
257 # FIXME: start here
258 def n_list_unpack(node):
259 """
260 prettyprint an unpacked list or tuple
261 """
262 p = self.prec
263 self.prec = 100
264 lastnode = node.pop()
265 lastnodetype = lastnode.kind
266
267 # If this build list is inside a CALL_FUNCTION_VAR,
268 # then the first * has already been printed.
269 # Until I have a better way to check for CALL_FUNCTION_VAR,
270 # will assume that if the text ends in *.
271 last_was_star = self.f.getvalue().endswith("*")
272
273 if lastnodetype.startswith("BUILD_LIST"):
274 self.write("[")
275 endchar = "]"
276 elif lastnodetype.startswith("BUILD_TUPLE"):
277 # Tuples can appear places that can NOT
278 # have parenthesis around them, like array
279 # subscripts. We check for that by seeing
280 # if a tuple item is some sort of slice.
281 no_parens = False
282 for n in node:
283 if n == "expr" and n[0].kind.startswith("build_slice"):
284 no_parens = True
285 break
286 pass
287 if no_parens:
288 endchar = ""
289 else:
290 self.write("(")
291 endchar = ")"
292 pass
293
294 elif lastnodetype.startswith("BUILD_SET"):
295 self.write("{")
296 endchar = "}"
297 elif lastnodetype.startswith("BUILD_MAP_UNPACK"):
298 self.write("{*")
299 endchar = "}"
300 elif lastnodetype.startswith("ROT_TWO"):
301 self.write("(")
302 endchar = ")"
303 else:
304 raise TypeError(
305 "Internal Error: n_build_list expects list, tuple, set, or unpack"
306 )
307
308 flat_elems = flatten_list(node)
309
310 self.indent_more(INDENT_PER_LEVEL)
311 sep = ""
312 for elem in flat_elems:
313 if elem in ("ROT_THREE", "EXTENDED_ARG"):
314 continue
315 assert elem == "expr"

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