Boolean object property in Python function parameter
JYone3A opened this issue · 1 comments
JYone3A commented
var s = {
a: "asd",
b: 1,
c: true,
};
let rtn = await python`print(${s})`;
The s.c parameter leads to an exception thrown. Strings/numbers work, arrays as well. Only boolean and null values (including NaN) throw errors:
(node:4232) UnhandledPromiseRejectionWarning: Error: Traceback (most recent call last):
File "...\node_modules\python-bridge\node_python_bridge.py", line 94, in <module>
value = eval(_compile(data['code'], '<input>', 'eval'), _locals)
File "<input>", line 1, in <module>
NameError: name 'true' is not defined
The easiest solution I found was to adapt _locals
, but I have no idea if that leads to other problems (maybe also for Infinity/NaN?):
_locals = {'__name__': '__console__', '__doc__': None, 'true': True, 'false': False, 'null': None}
The cleaner solution could be to use json.loads
to convert JSON input strings to a Python dict?
munro commented
Fixed in python-bridge@1.1.0
!