Skip to content

Commit 514b0d0

Browse files
committed
Sync from decompyle3
1 parent 283e493 commit 514b0d0

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

uncompyle6/parsers/reducecheck/while1stmt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def while1stmt(self, lhs, n, rule, ast, tokens, first, last):
3737
if tokens[loop_end] == "JUMP_BACK":
3838
loop_end += 1
3939
loop_end_offset = tokens[loop_end].off2int(prefer_last=False)
40-
for t in range(first+1, loop_end):
40+
for t in range(first + 1, loop_end):
4141
token = tokens[t]
4242
# token could be a pseudo-op like "LOAD_STR", which is not in
4343
# token.opc. We will replace that with LOAD_CONST as an
@@ -46,6 +46,5 @@ def while1stmt(self, lhs, n, rule, ast, tokens, first, last):
4646
if token.attr >= loop_end_offset:
4747
return True
4848

49-
5049
# SETUP_LOOP location must jump either to the last token or the token after the last one
5150
return tokens[first].attr not in (offset, offset + 2)

uncompyle6/semantics/make_function36.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2021 by Rocky Bernstein
1+
# Copyright (c) 2019-2022 by Rocky Bernstein
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -156,7 +156,7 @@ def build_param(ast, name, default, annotation=None):
156156
defparams.reverse()
157157

158158
try:
159-
ast = self.build_ast(
159+
tree = self.build_ast(
160160
scanner_code._tokens,
161161
scanner_code._customize,
162162
scanner_code,
@@ -176,7 +176,9 @@ def build_param(ast, name, default, annotation=None):
176176
if defparams:
177177
for i, defparam in enumerate(defparams):
178178
params.append(
179-
build_param(paramnames[i], defparam, annotate_dict.get(paramnames[i]))
179+
build_param(
180+
tree, paramnames[i], defparam, annotate_dict.get(paramnames[i])
181+
)
180182
)
181183

182184
for param in paramnames[i + 1 :]:
@@ -204,24 +206,30 @@ def build_param(ast, name, default, annotation=None):
204206

205207
# dump parameter list (with default values)
206208
if is_lambda:
207-
self.write("lambda ", ", ".join(params))
209+
self.write("lambda")
210+
if len(params):
211+
self.write(" ", ", ".join(params))
212+
elif kwonlyargcount > 0 and not (4 & code.co_flags):
213+
assert argc == 0
214+
self.write(" ")
215+
208216
# If the last statement is None (which is the
209217
# same thing as "return None" in a lambda) and the
210218
# next to last statement is a "yield". Then we want to
211219
# drop the (return) None since that was just put there
212220
# to have something to after the yield finishes.
213221
# FIXME: this is a bit hoaky and not general
214222
if (
215-
len(ast) > 1
216-
and self.traverse(ast[-1]) == "None"
217-
and self.traverse(ast[-2]).strip().startswith("yield")
223+
len(tree) > 1
224+
and self.traverse(tree[-1]) == "None"
225+
and self.traverse(tree[-2]).strip().startswith("yield")
218226
):
219-
del ast[-1]
227+
del tree[-1]
220228
# Now pick out the expr part of the last statement
221-
ast_expr = ast[-1]
222-
while ast_expr.kind != "expr":
223-
ast_expr = ast_expr[0]
224-
ast[-1] = ast_expr
229+
tree_expr = tree[-1]
230+
while tree_expr.kind != "expr":
231+
tree_expr = tree_expr[0]
232+
tree[-1] = tree_expr
225233
pass
226234
else:
227235
self.write("(", ", ".join(params))
@@ -331,11 +339,11 @@ def build_param(ast, name, default, annotation=None):
331339
# docstring exists, dump it
332340
self.println(self.traverse(node[-2]))
333341

334-
assert ast == "stmts"
342+
assert tree in ("stmts", "lambda_start")
335343

336-
all_globals = find_all_globals(ast, set())
344+
all_globals = find_all_globals(tree, set())
337345
globals, nonlocals = find_globals_and_nonlocals(
338-
ast, set(), set(), code, self.version
346+
tree, set(), set(), code, self.version
339347
)
340348

341349
for g in sorted((all_globals & self.mod_globs) | globals):
@@ -346,9 +354,9 @@ def build_param(ast, name, default, annotation=None):
346354

347355
self.mod_globs -= all_globals
348356
has_none = "None" in code.co_names
349-
rn = has_none and not find_none(ast)
357+
rn = has_none and not find_none(tree)
350358
self.gen_source(
351-
ast,
359+
tree,
352360
code.co_name,
353361
scanner_code._customize,
354362
is_lambda=is_lambda,

0 commit comments

Comments
 (0)