Skip to content

Commit c57ae70

Browse files
committed
Some more python 3 compatibility changes.
Avoiding name shadowing, iterating a changing structure, and concatenating dictionaries.
1 parent 3539a24 commit c57ae70

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
@@ -104,7 +104,7 @@ def find_main(self):
104104
mtds = []
105105
for c in self.clss:
106106
m = utils.extract_nodes([MethodDeclaration], c)
107-
mtds.extend([m for m in m if m.name == u'main'])
107+
mtds.extend([md for md in m if md.name == u'main'])
108108
# do we care if main is static?
109109
# mtds.extend(filter(lambda m: td.isStatic(m) and m.name == u'main', m))
110110
lenn = len(mtds)
@@ -417,7 +417,7 @@ def gen_adt_constructor(mtd):
417417
typ = self.tltr.trans_ty(t)
418418
if isinstance(t, ReferenceType) and t.arrayCount > 0:
419419
typ = "Array_"+typ
420-
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:
420+
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:
421421
typ = u'Object'
422422

423423
# if p.typee.name in p.symtab:
@@ -446,7 +446,7 @@ def gen_obj_constructor(mtd):
446446
ptyps = []
447447
ptyps_name = []
448448
for t in mtd_param_typs:
449-
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:
449+
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:
450450
typ = u'Object'
451451
else:
452452
typ = self.tltr.trans_ty(t)
@@ -554,7 +554,7 @@ def gen_obj_constructor(mtd):
554554
buf.write(self.to_func(m) + os.linesep)
555555

556556
# add bang functions for non-pure methods
557-
for (m,i) in zip(adt_mtds, xrange(len(adt_mtds))):
557+
for (m,i) in list(zip(adt_mtds, xrange(len(adt_mtds)))):
558558
if not m.pure:
559559
if not m.constructor:
560560
mtd = cp.copy(m)
@@ -595,8 +595,8 @@ def gen_obj_constructor(mtd):
595595

596596
# updates n's symbol table to include parents symbol table items
597597
def cpy_sym(n, *args):
598-
if n.parentNode: n.symtab = dict(n.parentNode.symtab.items() +
599-
n.symtab.items())
598+
if n.parentNode: n.symtab = dict(list(n.parentNode.symtab.items()) +
599+
list(n.symtab.items()))
600600

601601
# Iterates through ADT constructors
602602
# Creates a dictionary of xforms using constructor names
@@ -813,14 +813,14 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames):
813813
# add a symbol table items to xf
814814
# this will give it access to the argument names of a
815815
# then updates xf children with
816-
xf.symtab = dict(a.symtab.items() + xf.symtab.items())
816+
xf.symtab = dict(list(a.symtab.items()) + list(xf.symtab.items()))
817817
for c in xf.childrenNodes:
818818
utils.walk(cpy_sym, c)
819819

820820
# NOT SURE WHY THIS IS NEEDED
821821
# without this it isn't able to resolve the string type of the
822822
# function. not sure why...
823-
a.symtab = dict(xf.symtab.items() + a.symtab.items())
823+
a.symtab = dict(list(xf.symtab.items()) + list(a.symtab.items()))
824824
for c in a.childrenNodes:
825825
utils.walk(cpy_sym, c)
826826

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)