File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 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#
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments