Skip to content

Commit 1bdaf9e

Browse files
author
hartsantler
committed
fixed initialize dict with keys:values
both init styles work: literal {'x':1} and functional dict(x=1)
1 parent 814a8c1 commit 1bdaf9e

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

pythonscript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PythonScript Runtime - regenerated on: Wed Oct 9 02:45:12 2013
1+
// PythonScript Runtime - regenerated on: Wed Oct 9 06:17:34 2013
22
var jsrange = function(num) {
33
"Emulates Python's range function";
44
var i, r;

pythonscript/python_to_pythonjs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ def visit_Dict(self, node):
235235
keys = [x.s for x in node.keys]
236236
values = map(self.visit, node.values)
237237
a = [ '%s=%s'%x for x in zip(keys, values) ]
238-
return 'get_attribute(dict, "__call__")([], JSObject(%s))' % ', '.join(a)
238+
b = 'js_object=JSObject(%s)' %', '.join(a)
239+
return 'get_attribute(dict, "__call__")([], JSObject(%s))' % b
239240

240241
def visit_Tuple(self, node):
241242
## TODO how to deal with tuples
@@ -679,7 +680,10 @@ def visit_Call(self, node):
679680

680681
name = self.visit(node.func)
681682
if call_has_args:
682-
return 'get_attribute(%s, "__call__")(%s, %s)' % (name, args_name, kwargs_name)
683+
if name == 'dict':
684+
return 'get_attribute(%s, "__call__")(%s, JSObject(js_object=%s))' % (name, args_name, kwargs_name)
685+
else:
686+
return 'get_attribute(%s, "__call__")(%s, %s)' % (name, args_name, kwargs_name)
683687
elif name in self._classes:
684688
return 'get_attribute(%s, "__call__")( JSArray(), JSObject() )' %name
685689
else:

tests/test_dict.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
def test():
88
global d, l
9-
d = dict(a=1, b=2)
9+
10+
d = dict(a=1, b=2) ## functional style
1011
print( d['a'] )
1112
print( d['b'] )
1213
print( len(d) )
13-
print( d )
1414

1515
d['a'] = 'hello'
1616
d['b'] = 'world'
17+
d['c'] = 'foobar'
1718
print( d['a'] )
1819
print( d['b'] )
20+
print( d['c'] )
1921
print( len(d) )
2022

21-
22-
l = {'x':3, 'y':4}
23+
l = {'x':3, 'y':4} ## literal style
2324
print( l['x'] )
2425
print( l['y'] )
2526
l['x'] = 'XXX'

0 commit comments

Comments
 (0)