Skip to content

Commit 54f3256

Browse files
author
hartsantler
committed
fixed calling a function that expects kwargs, but the caller passes plain args, do not use kwarg defaults.
added server.py --regenerate-runtime updated runtime
1 parent 50f72d2 commit 54f3256

6 files changed

Lines changed: 39 additions & 8 deletions

File tree

bindings/three.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,9 @@ def position(self):
450450
@property
451451
def rotation(self):
452452
vec = self._object.rotation
453+
return Vector3( object=vec )
454+
455+
@property
456+
def scale(self):
457+
vec = self._object.scale
453458
return Vector3( object=vec )

pythonscript.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PythonScript Runtime - regenerated on: Mon Oct 7 03:32:19 2013
1+
// PythonScript Runtime - regenerated on: Mon Oct 7 06:29:29 2013
22
var jsrange = function(num) {
33
"Emulates Python's range function";
44
var i, r;
@@ -304,22 +304,34 @@ if(kwarg) {
304304
out[arg] = kwarg;
305305
}
306306
else {
307+
if(j < args.length) {
308+
out[arg] = args[j];
309+
}
310+
else {
307311
if(arg in signature.kwargs) {
308312
out[arg] = signature.kwargs[arg];
309313
}
310314
else {
311-
out[arg] = args[j];
315+
throw TypeError;
316+
}
317+
312318
}
313319

314320
}
315321

322+
}
323+
else {
324+
if(j < args.length) {
325+
out[arg] = args[j];
316326
}
317327
else {
318328
if(arg in signature.kwargs) {
319329
out[arg] = signature.kwargs[arg];
320330
}
321331
else {
322-
out[arg] = args[j];
332+
throw TypeError;
333+
}
334+
323335
}
324336

325337
}

runtime/pythonpythonjs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,20 @@ def get_arguments(signature, args, kwargs):
205205
kwarg = kwargs[arg]
206206
if kwarg:
207207
out[arg] = kwarg
208+
elif j < args.length:
209+
out[arg] = args[j]
208210
elif arg in signature.kwargs:
209211
out[arg] = signature.kwargs[arg]
210212
else:
211-
out[arg] = args[j]
213+
#out[arg] = args[j]
214+
raise TypeError
215+
elif j < args.length:
216+
out[arg] = args[j]
212217
elif arg in signature.kwargs:
213218
out[arg] = signature.kwargs[arg]
214219
else:
215-
out[arg] = args[j]
220+
#out[arg] = args[j]
221+
raise TypeError
216222
j += 1
217223
args = args.slice(j)
218224
if signature.vararg:

tests/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import tornado.ioloop
1515
import tornado.web
16-
import os, subprocess, datetime
16+
import os, sys, subprocess, datetime
1717

1818
PATHS = dict(
1919
webroot = os.path.dirname(os.path.abspath(__file__)),
@@ -28,7 +28,7 @@
2828

2929
)
3030

31-
REGENERATE_RUNTIME = True ## to be safer, the runtime should be rebuilt each run
31+
REGENERATE_RUNTIME = '--regenerate-runtime' in sys.argv
3232

3333
def python_to_pythonjs( src, module=None ):
3434
cmdheader = '#!%s' %PATHS['module_cache']

tests/test_calling_args_and_kwargs.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
print('testing mixed args and kwargs')
1313
print a,b, x,y,z
1414

15+
def test_simple(x,y):
16+
print x,y
17+
1518
def test():
1619
print('hello world')
1720
test_kwargs()
@@ -21,6 +24,11 @@
2124
mixed_args_kwargs(9,9)
2225
mixed_args_kwargs(9,9, z=420)
2326

27+
test_kwargs(3, 2, 1)
28+
29+
test_simple(1,2)
30+
test_simple(1) ## calling with too few args throw a TypeError
31+
2432
</script>
2533
</head>
2634

tests/test_threejs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from three import *
99

1010
def test():
11-
v = Vector3(1, 2, 3)
11+
v = Vector3(1, 2, z=3)
1212
print( v.x )
1313
print( v.y )
1414
print( v.z )

0 commit comments

Comments
 (0)