brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser
BSD 3-Clause "New" or "Revised" License
6.4k stars 512 forks source link

Error printing empty string; JavascriptError: TypeError: Cannot read properties of null (reading '$method_cache') #2429

Closed clach04 closed 1 week ago

clach04 commented 6 months ago

Test case for https://brython.info/console.html (works fine in https://brython.info/tests/editor.html )

print('')

Result:

Brython 3.12.3 on Netscape 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Type "help", "copyright", "credits" or "license" for more information.
>>> print('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "VFS.interpreter.py", line 109, in write
    self.interpreter.write(*args,**kw)
  File "VFS.interpreter.py", line 534, in write
    self.cursor_to_end()
  File "VFS.interpreter.py", line 309, in cursor_to_end
    pos=len(last_child.text)
JavascriptError: TypeError: Cannot read properties of null (reading '$method_cache')
>>> 

Seen with Chrome (not tested anything else).

clach04 commented 6 months ago

Presumably this https://github.com/brython-dev/brython/blob/8ced3ea8006e00eadf69271ca71fcc6805d0addc/www/src/Lib/interpreter.py#L309 is the line where the error occurs

Untested possible code change:

pos = len(last_child.text or '')

Assuming ternary works (it seems to work in https://brython.info/console.html).

Not read how to build/test yet (not sure if I will, I was just playing around today).

PierreQuentel commented 6 months ago

Thanks for reporting this @clach04. The issue exists in the current release and on brython.info but is fixed in the current development version. I will publish a new release soon.

clach04 commented 6 months ago

Great! I had chance to do some playing around and have a useful to me mini-app https://clach04.github.io/brython_tip_calc/ (that can generate palindrome totals for tipping ) with essentially no code changes to the Python code... it needs some UI/UX work though as this was a quick experiment. Really nice work on Brython implementation and docs/samples!