guysv / ilua

Portable Lua kernel for Jupyter
GNU General Public License v2.0
115 stars 11 forks source link

Docstring crashing shell #4

Open Ymac101 opened 4 years ago

Ymac101 commented 4 years ago

When an illegal character is present in a function's docstring (e.g string.find()) the shell crashes altogether:

In [3]: string.find?
Signature: string.find(s, pattern [, init [, plain]])
Documentation:Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\ilua.exe\__main__.py", line 9, in <module>
  File "c:\python27\lib\site-packages\ilua\consoleapp.py", line 37, in main
    ILuaConsoleApp().run()
  File "c:\python27\lib\site-packages\ilua\consoleapp.py", line 34, in run
    ZMQTerminalIPythonApp.launch_instance(argv=['--kernel', 'lua'])
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_core\application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\python27\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\app.py", line 155, in start
    self.shell.mainloop()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 508, in mainloop
    self.interact()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 500, in interact
    self.run_cell(code, store_history=True)
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 564, in run_cell
    self.handle_execute_reply(msg_id, timeout=0.05)
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 592, in handle_execute_reply
    page.page(item['data']['text/plain'])
  File "c:\python27\lib\site-packages\IPython\core\page.py", line 274, in page
    return pager_page(data, start, screen_lines, pager_cmd)
  File "c:\python27\lib\site-packages\IPython\core\page.py", line 201, in pager_page
    print(str_toprint)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xa7' in position 46: character maps to <undefined>
guysv commented 4 years ago

hmm, im pretty sure I patched that on 0.2.0, but ill give it a look!

guysv commented 4 years ago

works for me on 0.2.1: are you sure you're using the latest release? if not, what's your lua's version?

C:\Users\User>ilua
Jupyter console 5.3.0dev

ILua 0.2.1

In [1]: string.find?
Signature: string.find(s, pattern [, init [, plain]])
Documentation:
Looks for the first match of `pattern` (see §6.4.1) in the string `s`. If it
finds a match, then `find` returns the indices of `s` where this occurrence
starts and ends; otherwise, it returns **nil**. A third, optional numeric
argument `init` specifies where to start the search; its default value is 1
and can be negative. A value of **true** as a fourth, optional argument
`plain` turns off the pattern matching facilities, so the function does a
plain "find substring" operation, with no characters in `pattern` being
considered magic. Note that if `plain` is given, then `init` must be given as
well.

If the pattern has captures, then in a successful match the captured values
are also returned, after the two indices.
Path: n/a
guysv commented 4 years ago

Wait, my bad. I was actually using a modified version of jupyter_console that fixed this bug here is my upstream PR: https://github.com/jupyter/jupyter_console/pull/177 Unfortunately, Jupyter is yet to merge that PR, so I probably set a workaround at the scope of this project.