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

Function n_build_list_unpack

uncompyle6/semantics/customize35.py:80–140  ·  view source on GitHub ↗

prettyprint a list or tuple

(node)

Source from the content-addressed store, hash-verified

78 self.n_async_call = async_call
79
80 def n_build_list_unpack(node):
81 """
82 prettyprint a list or tuple
83 """
84 p = self.prec
85 self.prec = 100
86 lastnode = node.pop()
87 lastnodetype = lastnode.kind
88
89 # If this build list is inside a CALL_FUNCTION_VAR,
90 # then the first * has already been printed.
91 # Until I have a better way to check for CALL_FUNCTION_VAR,
92 # will assume that if the text ends in *.
93 last_was_star = self.f.getvalue().endswith("*")
94
95 if lastnodetype.startswith("BUILD_LIST"):
96 self.write("[")
97 endchar = "]"
98 else:
99 endchar = ""
100
101 flat_elems = flatten_list(node)
102
103 self.indent_more(INDENT_PER_LEVEL)
104 sep = ""
105 for elem in flat_elems:
106 if elem in ("ROT_THREE", "EXTENDED_ARG"):
107 continue
108 assert elem == "expr"
109 line_number = self.line_number
110 use_star = True
111 value = self.traverse(elem)
112 if value.startswith("("):
113 assert value.endswith(")")
114 use_star = False
115 value = value[1:-1].rstrip(
116 " "
117 ) # Remove starting "(" and trailing ")" and additional spaces
118 if value == "":
119 pass
120 else:
121 if value.endswith(","): # if args has only one item
122 value = value[:-1]
123 if line_number != self.line_number:
124 sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
125 else:
126 if sep != "":
127 sep += " "
128 if not last_was_star and use_star:
129 sep += "*"
130 pass
131 else:
132 last_was_star = False
133 self.write(sep, value)
134 sep = ","
135 self.write(endchar)
136 self.indent_less(INDENT_PER_LEVEL)
137

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