Skip to content

Commit 4ac5564

Browse files
committed
Don't remove LOAD_CONST RETURN_VALUE when...
the LOAD_CONST has a non-None value, or the LOAD_CONST has a line associated with it.
1 parent addddf8 commit 4ac5564

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

uncompyle6/scanners/tok.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016-2021, 2023 by Rocky Bernstein
1+
# Copyright (c) 2016-2021, 2023-2024 by Rocky Bernstein
22
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
33
# Copyright (c) 1999 John Aycock
44
#

uncompyle6/semantics/pysource.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,11 +1251,21 @@ def build_ast(
12511251
if tokens[-1].kind in ("RETURN_VALUE", "RETURN_VALUE_LAMBDA"):
12521252
# Python 3.4's classes can add a "return None" which is
12531253
# invalid syntax.
1254-
if tokens[-2].kind == "LOAD_CONST":
1255-
if is_top_level_module or tokens[-2].pattr is None:
1256-
del tokens[-2:]
1257-
else:
1258-
tokens.append(Token("RETURN_LAST"))
1254+
load_const = tokens[-2]
1255+
# We should have:
1256+
# LOAD_CONST None
1257+
# with *no* line number associated the token.
1258+
# A line number on the token or a non-None
1259+
# token value a token based on user source
1260+
# text.
1261+
if (
1262+
load_const.kind == "LOAD_CONST"
1263+
and load_const.linestart is None
1264+
and load_const.attr is None
1265+
or is_top_level_module
1266+
):
1267+
# Delete LOAD_CONST (None) RETURN_VALUE
1268+
del tokens[-2:]
12591269
else:
12601270
tokens.append(Token("RETURN_LAST"))
12611271
if len(tokens) == 0:

0 commit comments

Comments
 (0)