Track grammar "stmt" simplifications class ...

* NAME_MODULE constant
* QUAL_NAME constant
This commit is contained in:
rocky
2020-01-29 15:37:58 -05:00
parent b548910e57
commit fdf4496a2d
4 changed files with 27 additions and 29 deletions

View File

@@ -32,14 +32,16 @@ SKIP_TESTS=(
[test_doctest2.py]=1 # FIXME: assert failure - works on decompyle3 [test_doctest2.py]=1 # FIXME: assert failure - works on decompyle3
[test_docxmlrpc.py]=1 [test_docxmlrpc.py]=1
[test_enum.py]=1 # probably bad control flow [test_enum.py]=1 # probably bad control flow
[test_faulthandler.py]=1 # takes too long [test_faulthandler.py]=1 # takes too long
[test_fcntl.py]=1 [test_fcntl.py]=1
[test_fileinput.py]=1 # Test assertion failures [test_fileinput.py]=1 # Test assertion failures
[test_format.py]=1 # Probably not handling bytestrings properly [test_format.py]=1 # Probably not handling bytestrings properly
[test_frame.py]=1 # test assertion errors [test_frame.py]=1 # test assertion errors
[test_ftplib.py]=1 # parse error [test_ftplib.py]=1 # parse error
[test_functools.py]=1 # parse error
[test_fstring.py]=1 # need to disambiguate leading fstrings from docstrings [test_fstring.py]=1 # need to disambiguate leading fstrings from docstrings
[test_functools.py]=1 # parse error
[test_gdb.py]=1 # it fails on its own [test_gdb.py]=1 # it fails on its own
[test_generators.py]=1 # Investigate improper lamdba with bogus "False" added [test_generators.py]=1 # Investigate improper lamdba with bogus "False" added
[test_glob.py]=1 # TypeError: join() argument must be str or bytes, not 'tuple' [test_glob.py]=1 # TypeError: join() argument must be str or bytes, not 'tuple'

View File

@@ -1,6 +1,8 @@
SKIP_TESTS=( SKIP_TESTS=(
[test___all__.py]=1 # it fails on its own [test___all__.py]=1 # it fails on its own
[test_aifc.py]=1 # parse error
[test_argparse.py]=1 #- it fails on its own [test_argparse.py]=1 #- it fails on its own
[test_array.py]=1 #- parse error
[test_asdl_parser.py]=1 # it fails on its own [test_asdl_parser.py]=1 # it fails on its own
[test_ast.py]=1 # Depends on comments in code [test_ast.py]=1 # Depends on comments in code
[test_atexit.py]=1 # The atexit test looks for specific comments in error lines [test_atexit.py]=1 # The atexit test looks for specific comments in error lines
@@ -14,9 +16,9 @@ SKIP_TESTS=(
[test_cmath.py]=1 # test assertion failure [test_cmath.py]=1 # test assertion failure
[test_cmd_line.py]=1 # Interactive? [test_cmd_line.py]=1 # Interactive?
[test_cmd_line_script.py]=1 [test_cmd_line_script.py]=1
[test_codecs.py]=1
[test_collections.py]=1 [test_collections.py]=1
[test_compare.py]=1 [test_compare.py]=1
[test_compileall.py]=1 # fails on its own
[test_compile.py]=1 [test_compile.py]=1
[test_concurrent_futures.py]=1 # too long [test_concurrent_futures.py]=1 # too long
[test_configparser.py]=1 [test_configparser.py]=1

View File

@@ -136,25 +136,25 @@ PASS = SyntaxTree('stmts',
[ SyntaxTree('pass', [])])])]) [ SyntaxTree('pass', [])])])])
ASSIGN_DOC_STRING = lambda doc_string, doc_load: \ ASSIGN_DOC_STRING = lambda doc_string, doc_load: \
SyntaxTree('stmt', SyntaxTree("stmt",
[ SyntaxTree('assign', [ SyntaxTree("assign",
[ SyntaxTree('expr', [ Token(doc_load, pattr=doc_string, attr=doc_string) ]), [ SyntaxTree("expr", [ Token(doc_load, pattr=doc_string, attr=doc_string) ]),
SyntaxTree('store', [ Token('STORE_NAME', pattr='__doc__')]) SyntaxTree("store", [ Token("STORE_NAME", pattr="__doc__")])
])]) ])])
NAME_MODULE = SyntaxTree('stmt', NAME_MODULE = SyntaxTree("sstmt",
[ SyntaxTree('assign', [ SyntaxTree("assign",
[ SyntaxTree('expr', [ SyntaxTree("expr",
[Token('LOAD_NAME', pattr='__name__', offset=0, has_arg=True)]), [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True)]),
SyntaxTree('store', SyntaxTree("store",
[ Token('STORE_NAME', pattr='__module__', offset=3, has_arg=True)]) [ Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True)])
])]) ])])
# God intended \t, but Python has decided to use 4 spaces. # God intended \t, but Python has decided to use 4 spaces.
# If you want real tabs, use Go. # If you want real tabs, use Go.
# TAB = '\t' # TAB = "\t"
TAB = ' ' * 4 TAB = " " * 4
INDENT_PER_LEVEL = ' ' # additional intent per pretty-print level INDENT_PER_LEVEL = " " # additional intent per pretty-print level
TABLE_R = { TABLE_R = {
'STORE_ATTR': ( '%c.%[1]{pattr}', 0), 'STORE_ATTR': ( '%c.%[1]{pattr}', 0),

View File

@@ -2115,7 +2115,6 @@ class SourceWalker(GenericASTTraversal, object):
try: try:
self.write(eval(expr, d, d)) self.write(eval(expr, d, d))
except: except:
from trepan.api import debug; debug()
raise raise
m = escape.search(fmt, i) m = escape.search(fmt, i)
self.write(fmt[i:]) self.write(fmt[i:])
@@ -2272,13 +2271,13 @@ class SourceWalker(GenericASTTraversal, object):
self.println(self.traverse(ast[0])) self.println(self.traverse(ast[0]))
del ast[0] del ast[0]
first_stmt = ast[0][0] first_stmt = ast[0]
if 3.0 <= self.version <= 3.3: if 3.0 <= self.version <= 3.3:
try: try:
if first_stmt[0] == "store_locals": if first_stmt == "store_locals":
if self.hide_internal: if self.hide_internal:
del ast[0] del ast[0]
first_stmt = ast[0][0] first_stmt = ast[0]
except: except:
pass pass
@@ -2286,7 +2285,7 @@ class SourceWalker(GenericASTTraversal, object):
if first_stmt == NAME_MODULE: if first_stmt == NAME_MODULE:
if self.hide_internal: if self.hide_internal:
del ast[0] del ast[0]
first_stmt = ast[0][0] first_stmt = ast[0]
pass pass
except: except:
pass pass
@@ -2296,9 +2295,6 @@ class SourceWalker(GenericASTTraversal, object):
# Should we ditch this in favor of the "else" case? # Should we ditch this in favor of the "else" case?
qualname = ".".join(self.classes) qualname = ".".join(self.classes)
QUAL_NAME = SyntaxTree( QUAL_NAME = SyntaxTree(
"stmt",
[
SyntaxTree(
"assign", "assign",
[ [
SyntaxTree("expr", [Token("LOAD_CONST", pattr=qualname)]), SyntaxTree("expr", [Token("LOAD_CONST", pattr=qualname)]),
@@ -2307,8 +2303,6 @@ class SourceWalker(GenericASTTraversal, object):
), ),
], ],
) )
],
)
have_qualname = ast[0][0] == QUAL_NAME have_qualname = ast[0][0] == QUAL_NAME
else: else:
# Python 3.4+ has constants like 'cmp_to_key.<locals>.K' # Python 3.4+ has constants like 'cmp_to_key.<locals>.K'