diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index 0e701e97..75a56912 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021, 2023 by Rocky Bernstein +# Copyright (c) 2016-2021, 2023-2024 by Rocky Bernstein # Copyright (c) 2000-2002 by hartmut Goebel # Copyright (c) 1999 John Aycock # diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 00138023..78fd4e8c 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1251,11 +1251,21 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin): if tokens[-1].kind in ("RETURN_VALUE", "RETURN_VALUE_LAMBDA"): # Python 3.4's classes can add a "return None" which is # invalid syntax. - if tokens[-2].kind == "LOAD_CONST": - if is_top_level_module or tokens[-2].pattr is None: - del tokens[-2:] - else: - tokens.append(Token("RETURN_LAST")) + load_const = tokens[-2] + # We should have: + # LOAD_CONST None + # with *no* line number associated the token. + # A line number on the token or a non-None + # token value a token based on user source + # text. + if ( + load_const.kind == "LOAD_CONST" + and load_const.linestart is None + and load_const.attr is None + or is_top_level_module + ): + # Delete LOAD_CONST (None) RETURN_VALUE + del tokens[-2:] else: tokens.append(Token("RETURN_LAST")) if len(tokens) == 0: