mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-02-17 03:38:13 +00:00
Correct long-literals for Python 2.7
This commit is contained in:
parent
bb9b9fb4b3
commit
5b3ea47bac
Binary file not shown.
Binary file not shown.
@ -161,7 +161,9 @@ x = {
|
||||
"return": 12,
|
||||
}
|
||||
|
||||
assert tuple(x.keys()) == ("b", "c", "e", "g", "h", "j", "k", "return")
|
||||
# We need sorted here and below, because x.keys() in 2.7 comes out in the reverse order.
|
||||
# Go figure.
|
||||
assert sorted(x.keys()) == ["b", "c", "e", "g", "h", "j", "k", "return"]
|
||||
|
||||
# Ensure that in dictionary we produce integers, not strings
|
||||
x = {1: 2, 3: 4}
|
||||
@ -675,7 +677,12 @@ values = {
|
||||
"value502": 502 + 1,
|
||||
}
|
||||
|
||||
assert list(values.values())[1:] == list(range(3, 502 + 2))
|
||||
import sys
|
||||
if sys.version < (3, 0):
|
||||
# Python 2.7 is funky with values.values() ordering
|
||||
assert sorted(values.values())[1:-2] == list(range(4, 502 + 1))
|
||||
else:
|
||||
assert list(values.values())[1:] == list(range(3, 502 + 2))
|
||||
|
||||
# Try a long dictionary that fails because we have a binary op.
|
||||
# We can get a expr32 grouping speedup
|
||||
@ -717,4 +724,4 @@ values = {
|
||||
"value33": 33,
|
||||
}
|
||||
|
||||
assert list(values.values())[1:] == list(range(2, 34))
|
||||
assert sorted(values.values())[1:] == list(range(2, 34))
|
||||
|
@ -99,7 +99,7 @@ class PythonParser(GenericASTBuilder):
|
||||
# so on but that would require major changes to the
|
||||
# semantic actions
|
||||
self.singleton = frozenset(
|
||||
("str", "store", "_stmts", "suite_stmts_opt", "inplace_op")
|
||||
("str", "store", "_stmts", "suite_stmts_opt", "inplace_op", "add_value")
|
||||
)
|
||||
# Instructions filled in from scanner
|
||||
self.insts = []
|
||||
|
@ -315,7 +315,9 @@ class Python2Parser(PythonParser):
|
||||
if opname in ("BUILD_CONST_LIST", "BUILD_CONST_SET"):
|
||||
rule = (
|
||||
"""
|
||||
add_consts ::= ADD_VALUE*
|
||||
add_consts ::= add_value+
|
||||
add_value ::= ADD_VALUE
|
||||
add_value ::= ADD_VALUE_VAR
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
expr ::= const_list
|
||||
"""
|
||||
|
@ -171,10 +171,14 @@ class Scanner(object):
|
||||
has_extended_arg=False,
|
||||
)
|
||||
)
|
||||
if tokens[j] == "LOAD_CONST":
|
||||
opname = "ADD_VALUE"
|
||||
else:
|
||||
opname = "ADD_VALUE_VAR"
|
||||
for j in range(collection_start, i):
|
||||
new_tokens.append(
|
||||
Token(
|
||||
opname="ADD_VALUE",
|
||||
opname=opname,
|
||||
attr=tokens[j].attr,
|
||||
pattr=tokens[j].pattr,
|
||||
offset=tokens[j].offset,
|
||||
|
@ -25,7 +25,6 @@ from xdis import (
|
||||
)
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6.semantics.helper import (
|
||||
find_all_globals,
|
||||
find_globals_and_nonlocals,
|
||||
|
@ -257,11 +257,14 @@ class NonterminalActions:
|
||||
sep = ", "
|
||||
else:
|
||||
for elem in flat_elems:
|
||||
assert elem.kind == "ADD_VALUE"
|
||||
try:
|
||||
if elem == "add_value":
|
||||
elem = elem[0]
|
||||
if elem == "ADD_VALUE":
|
||||
value = "%r" % elem.pattr
|
||||
except Exception:
|
||||
value = elem.pattr
|
||||
else:
|
||||
assert elem.kind == "ADD_VALUE_VAR"
|
||||
value = "%s" % elem.pattr
|
||||
|
||||
if elem.linestart is not None:
|
||||
if elem.linestart != self.line_number:
|
||||
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user