Skip to content

Commit 88c6c87

Browse files
committed
Some more python 3 compatibility changes.
Avoiding name shadowing, iterating a changing structure, and concatenating dictionaries.
1 parent 80d7aa8 commit 88c6c87

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

java_sk/encoder.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def find_main(self):
102102
mtds = []
103103
for c in self.clss:
104104
m = utils.extract_nodes([MethodDeclaration], c)
105-
mtds.extend([m for m in m if m.name == u'main'])
105+
mtds.extend([md for md in m if md.name == u'main'])
106106
# do we care if main is static?
107107
# mtds.extend(filter(lambda m: td.isStatic(m) and m.name == u'main', m))
108108
lenn = len(mtds)
@@ -384,7 +384,7 @@ def gen_adt_constructor(mtd):
384384
typ = self.tltr.trans_ty(t)
385385
if isinstance(t, ReferenceType) and t.arrayCount > 0:
386386
typ = "Array_"+typ
387-
if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls:
387+
if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [axc.name for axc in self.ax_clss] and not self.is_ax_cls:
388388
typ = u'Object'
389389

390390
# if p.typee.name in p.symtab:
@@ -413,7 +413,7 @@ def gen_obj_constructor(mtd):
413413
ptyps = []
414414
ptyps_name = []
415415
for t in mtd_param_typs:
416-
if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls:
416+
if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [axc.name for axc in self.ax_clss] and not self.is_ax_cls:
417417
typ = u'Object'
418418
else:
419419
typ = self.tltr.trans_ty(t)
@@ -521,7 +521,7 @@ def gen_obj_constructor(mtd):
521521
buf.write(self.to_func(m) + os.linesep)
522522

523523
# add bang functions for non-pure methods
524-
for (m,i) in zip(adt_mtds, xrange(len(adt_mtds))):
524+
for (m,i) in list(zip(adt_mtds, xrange(len(adt_mtds)))):
525525
if not m.pure:
526526
if not m.constructor:
527527
mtd = cp.copy(m)
@@ -562,8 +562,8 @@ def gen_obj_constructor(mtd):
562562

563563
# updates n's symbol table to include parents symbol table items
564564
def cpy_sym(n, *args):
565-
if n.parentNode: n.symtab = dict(n.parentNode.symtab.items() +
566-
n.symtab.items())
565+
if n.parentNode: n.symtab = dict(list(n.parentNode.symtab.items()) +
566+
list(n.symtab.items()))
567567

568568
# Iterates through ADT constructors
569569
# Creates a dictionary of xforms using constructor names
@@ -780,14 +780,14 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames):
780780
# add a symbol table items to xf
781781
# this will give it access to the argument names of a
782782
# then updates xf children with
783-
xf.symtab = dict(a.symtab.items() + xf.symtab.items())
783+
xf.symtab = dict(list(a.symtab.items()) + list(xf.symtab.items()))
784784
for c in xf.childrenNodes:
785785
utils.walk(cpy_sym, c)
786786

787787
# NOT SURE WHY THIS IS NEEDED
788788
# without this it isn't able to resolve the string type of the
789789
# function. not sure why...
790-
a.symtab = dict(xf.symtab.items() + a.symtab.items())
790+
a.symtab = dict(list(xf.symtab.items()) + list(a.symtab.items()))
791791
for c in a.childrenNodes:
792792
utils.walk(cpy_sym, c)
793793

jskparser/ast/node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def add_parent_post(self, p, recurse=True):
249249
if self not in p.childrenNodes: p.childrenNodes.append(self)
250250
self.parentNode = p
251251
if p.symtab and self.symtab:
252-
self.symtab = dict(p.symtab.items() + self.symtab.items())
252+
self.symtab = dict(list(p.symtab.items()) + list(self.symtab.items()))
253253
elif p.symtab:
254254
self.symtab = copy.copy(p.symtab)
255255

jskparser/ast/visit/symtabgen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def visit(self, node):
163163
# Catch args that are actually Axiom Declarations
164164
if p.method:
165165
p.method.symtab.update(node.symtab)
166-
node.symtab = dict(p.method.symtab.items() + node.symtab.items())
166+
node.symtab = dict(list(p.method.symtab.items()) + list(node.symtab.items()))
167167
if node.body:
168168
node.body.accept(self)
169169
# print node.symtab

0 commit comments

Comments
 (0)