Skip to content

Commit 8a1fd7e

Browse files
committed
Keep optype info in token...
It is useful for ADD_VALUE
1 parent d2a1716 commit 8a1fd7e

File tree

10 files changed

+42
-21
lines changed

10 files changed

+42
-21
lines changed

test/stdlib/3.6-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SKIP_TESTS=(
22
[test_ast.py]=1 # FIXME: Works on c90ff51
3-
[test_cmath.py]=1 # FIXME: Works on c90ff51
3+
[test_cmath.py]=1 # fails on its own
44
[test_format.py]=1 # FIXME: Works on c90ff51
55
[test_ftplib.py]=1 # FIXME: Works on c90ff51
66
[test_slice.py]=1 # FIXME: Works on c90ff51

test/stdlib/3.7-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SKIP_TESTS=(
3636
[test_bdb.py]=1 #
3737
[test_buffer.py]=1 # parse error
3838
[test_clinic.py]=1 # it fails on its own
39-
[test_cmath.py]=1 # test assertion failure
39+
[test_cmath.py]=pytest
4040
[test_cmd_line.py]=1 # Interactive?
4141
[test_cmd_line_script.py]=1
4242
[test_compileall.py]=1 # fails on its own

test/stdlib/3.8-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ SKIP_TESTS=(
6969
[test_cgi.py]=1 # parse error
7070
[test_cgitb.py]=1 # parse error
7171
[test_clinic.py]=1 # it fails on its own
72-
[test_cmath.py]=1 # test assertion failure
72+
[test_cmath.py]=pytest
7373
[test_cmd.py]=1 # parse error
7474
[test_cmd_line.py]=1 # Interactive?
7575
[test_cmd_line_script.py]=1

test/stdlib/runtests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ if [[ -n $1 ]] ; then
189189
if (( ${#files_ary[@]} == 1 || DONT_SKIP_TESTS == 1 )) ; then
190190
for file in $files; do
191191
if (( SKIP_TESTS[$file] != "pytest" )); then
192-
SKIP_TESTS[$file] = 1;
192+
SKIP_TESTS[$file]=1;
193193
fi
194194
done
195195
fi

uncompyle6/scanners/scanner3.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def bound_collection_from_inst(
266266
has_arg=True,
267267
has_extended_arg=False,
268268
opc=self.opc,
269+
optype=None,
269270
)
270271
)
271272
for j in range(collection_start, i):
@@ -279,6 +280,7 @@ def bound_collection_from_inst(
279280
has_arg=True,
280281
has_extended_arg=False,
281282
opc=self.opc,
283+
optype=insts[j].optype,
282284
)
283285
)
284286
new_tokens.append(
@@ -291,6 +293,7 @@ def bound_collection_from_inst(
291293
has_arg=t.has_arg,
292294
has_extended_arg=False,
293295
opc=t.opc,
296+
optype=None,
294297
)
295298
)
296299
return new_tokens
@@ -339,6 +342,7 @@ def bound_map_from_inst(
339342
has_arg=True,
340343
has_extended_arg=False,
341344
opc=self.opc,
345+
optype=None,
342346
)
343347
)
344348
for j in range(collection_start, i, 2):
@@ -364,6 +368,7 @@ def bound_map_from_inst(
364368
has_arg=True,
365369
has_extended_arg=False,
366370
opc=self.opc,
371+
optype=insts[j + 1].optype,
367372
)
368373
)
369374
new_tokens.append(
@@ -376,6 +381,7 @@ def bound_map_from_inst(
376381
has_arg=t.has_arg,
377382
has_extended_arg=False,
378383
opc=t.opc,
384+
optype=t.optype,
379385
)
380386
)
381387
return new_tokens

uncompyle6/scanners/scanner37.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
from typing import Tuple
2626

27-
from uncompyle6.scanner import CONST_COLLECTIONS, Token
28-
from uncompyle6.scanners.scanner37base import Scanner37Base
29-
3027
# bytecode verification, verify(), uses JUMP_OPs from here
3128
from xdis.opcodes import opcode_37 as opc
3229

30+
from uncompyle6.scanner import CONST_COLLECTIONS, Token
31+
from uncompyle6.scanners.scanner37base import Scanner37Base
32+
3333
# bytecode verification, verify(), uses JUMP_OPS from here
3434
JUMP_OPs = opc.JUMP_OPS
3535

@@ -90,6 +90,7 @@ def bound_collection_from_tokens(
9090
has_arg=True,
9191
has_extended_arg=False,
9292
opc=self.opc,
93+
optype=None,
9394
)
9495
)
9596
for j in range(collection_start, i):
@@ -103,6 +104,7 @@ def bound_collection_from_tokens(
103104
has_arg=True,
104105
has_extended_arg=False,
105106
opc=self.opc,
107+
optype=tokens[j].optype,
106108
)
107109
)
108110
new_tokens.append(

uncompyle6/scanners/scanner37base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def tokens_append(j, token):
355355
has_arg=True,
356356
opc=self.opc,
357357
has_extended_arg=False,
358+
optype=inst.optype,
358359
),
359360
)
360361
jump_idx += 1
@@ -426,6 +427,7 @@ def tokens_append(j, token):
426427
has_arg=inst.has_arg,
427428
opc=self.opc,
428429
has_extended_arg=inst.has_extended_arg,
430+
optype=inst.optype,
429431
),
430432
)
431433
continue
@@ -527,6 +529,7 @@ def tokens_append(j, token):
527529
has_arg=inst.has_arg,
528530
opc=self.opc,
529531
has_extended_arg=inst.has_extended_arg,
532+
optype=inst.optype,
530533
),
531534
)
532535
pass

uncompyle6/scanners/tok.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ def __init__(
6161
opname,
6262
attr=None,
6363
pattr=None,
64-
offset:Union[int, str]=-1,
64+
offset: Union[int, str] = -1,
6565
linestart=None,
6666
op=None,
6767
has_arg=None,
6868
opc=None,
6969
has_extended_arg=False,
70+
optype=None,
7071
):
7172
self.kind = intern(opname)
7273
self.has_arg = has_arg
7374
self.attr = attr
7475
self.pattr = pattr
76+
self.optype = optype
7577
if has_extended_arg:
7678
self.offset = "%d_%d" % (offset, offset + 2)
7779
else:
@@ -107,8 +109,8 @@ def __init__(
107109
self.op = op
108110

109111
def __eq__(self, o):
110-
""" '==' on kind and "pattr" attributes.
111-
It is okay if offsets and linestarts are different"""
112+
"""'==' on kind and "pattr" attributes.
113+
It is okay if offsets and linestarts are different"""
112114
if isinstance(o, Token):
113115
return (self.kind == o.kind) and (
114116
(self.pattr == o.pattr) or self.attr == o.attr
@@ -118,7 +120,7 @@ def __eq__(self, o):
118120
return self.kind == o
119121

120122
def __ne__(self, o):
121-
""" '!=', but it's okay if offsets and linestarts are different"""
123+
"""'!=', but it's okay if offsets and linestarts are different"""
122124
return not self.__eq__(o)
123125

124126
def __repr__(self):

uncompyle6/semantics/consts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
SyntaxTree(
137137
"expr", [Token(doc_load, pattr=doc_string, attr=doc_string)]
138138
),
139-
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__")]),
139+
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__", optype="name")]),
140140
],
141141
)
142142

@@ -148,10 +148,10 @@
148148
"assign",
149149
[
150150
SyntaxTree(
151-
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True)]
151+
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True, optype="name")]
152152
),
153153
SyntaxTree(
154-
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True)]
154+
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True, optype="name")]
155155
),
156156
],
157157
)

uncompyle6/semantics/n_actions.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,15 @@ def n_const_list(self, node: SyntaxTree):
240240
assert len(keys) == len(flat_elems) - 1
241241
for i, elem in enumerate(flat_elems[:-1]):
242242
assert elem.kind == "ADD_VALUE"
243-
try:
244-
value = "%r" % elem.pattr
245-
except Exception:
246-
value = elem.pattr
243+
if elem.optype in ("local", "name"):
244+
value = elem.attr
245+
elif elem.optype == "const" and not isinstance(elem.attr, str):
246+
value = elem.attr
247+
else:
248+
try:
249+
value = "%r" % elem.pattr
250+
except Exception:
251+
value = elem.pattr
247252
if elem.linestart is not None:
248253
if elem.linestart != self.line_number:
249254
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
@@ -266,11 +271,14 @@ def n_const_list(self, node: SyntaxTree):
266271
for elem in flat_elems:
267272
if elem == "add_value":
268273
elem = elem[0]
274+
269275
if elem == "ADD_VALUE":
270-
if self.version < (3, 0, 0):
271-
value = "%r" % repr(elem.pattr)
276+
if elem.optype in ("local", "name"):
277+
value = elem.attr
278+
elif elem.optype == "const" and not isinstance(elem.attr, str):
279+
value = elem.attr
272280
else:
273-
value = "%s" % str(elem.pattr)
281+
value = "%s" % repr(elem.pattr)
274282
else:
275283
assert elem.kind == "ADD_VALUE_VAR"
276284
value = "%s" % elem.pattr

0 commit comments

Comments
 (0)