** operator on a JS object produces the error "attr keys of obj undef"
denis-migdal opened this issue · comments
Hi,
Somewhere in my code, I have opts
which is a JS object.
BLISS(**opts)
Produces :
attr keys of obj undef
Uncaught (in promise) TypeError: obj is undefined
$getattr http://127.0.0.1:5500/brython/www/src/brython.js:2903
anonymous http://127.0.0.1:5500/brython/www/src/brython.js line 11966 > Function:55
BLISS20 http://127.0.0.1:5500/brython/www/src/brython.js line 150 > Function:43
call http://127.0.0.1:5500/brython/www/src/brython.js:1603
BLISSAuto_defineWebComponent43 http://127.0.0.1:5500/brython/www/src/brython.js line 150 > Function:556
defineWebComponent http://127.0.0.1:5500/index.js:48
#addTag http://127.0.0.1:5500/LISS/index.js:603
LISS_Auto http://127.0.0.1:5500/LISS/index.js:562
BLISS_Auto http://127.0.0.1:5500/index.js:37
init http://127.0.0.1:5500/LISS/index.js:239
connectedCallback http://127.0.0.1:5500/LISS/index.js:190
define http://127.0.0.1:5500/LISS/index.js:328
async* http://127.0.0.1:5500/index.js:51
2 brython.js:2903:4
However, if I do :
opts = dict(opts)
BLISS(**opts)
It works properly.
I suggest either :
- raising an exception when using
**
on a JS objectCan't use ** operator on js object, use dict() to convert to dictionary
. - OR, when using
**
operator, if used on a JS object, first convert to a dictionary ?
Cordially,
With the commit above, an exception is raised:
Traceback (most recent call last):
File "tests/test.html", line 24, in <module>
f(**window.kw)
TypeError: s1.f() argument after ** must be a mapping, not Javascript Object
I think it's explicit enough, do you agree ?
I think it's explicit enough, do you agree ?
I think this is a good error message as it is very close to Python error messages, therefore we can find more information by searching the error message.
I think the error message could be more explicit, but that'd a Python issue, not a Brython issue.