Skip to content

"Run Selection/Line in Python terminal" with space before selection crashes iPython when interpreter is iPython (but not when it is Python) #2500

Closed
@Hugo-W

Description

@Hugo-W

This is a behaviour that is also quite used in a data science way, to run code within for loops for instance, which works well in Spyder, or iPython consoles in general. Running a line of code that has indentation should be possible when there is only one line (or several with same indentation).
Could eventually be integrated along #169 ?

Environment data

  • VS Code version: 1.26.1
  • Python-vscode: 2018.8.0
  • Linux Mint 18.1
  • Anaconda Python 3.6
  • virtual environment used: conda
  • iPython 6.4.0

Actual behavior

When running command "Run Selection/Line" with iPython interpreter on a line with indentation, it throws an error and iPython is closed...
Though, this works as I expect with Python interpeter when run inside an ipython terminal (my usual workaround anyway), that is: it runs the line (the string sent to the terminal will contain spaces before the text but the command runs without error). However, this contains error in the Console from developer tools (ses below).

Here is a gif showing the whole behaviour (Note: on the GIF, I am under another conda environment, Python 2.7 and Ipython 5.1.0 but I get exactly the same behaviour/error logs):
demobug

Expected behavior

To run the selected line

Steps to reproduce:

  1. Set interpreter (settings python.pythonPath) to ipython
  2. "Run Selection/Line in Python Terminal" on a line with indentation

Logs

Traceback within Python terminal (running iPython, when iPython is the set interpreter for the extension):

Traceback (most recent call last):
  File "/home/hugo/anaconda2/envs/py36/bin/ipython", line 11, in <module>
    sys.exit(start_ipython())
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/__init__.py", line 125, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 356, in start
    self.shell.mainloop()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 485, in mainloop
    self.interact()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 468, in interact
    code = self.prompt_for_code()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 381, in prompt_for_code
    pre_run=self.pre_prompt, reset_current_buffer=True)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/interface.py", line 415, in run
    self.eventloop.run(self.input, self.create_eventloop_callbacks())
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/eventloop/posix.py", line 159, in run
    t()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/eventloop/posix.py", line 82, in read_from_stdin
    inputstream.feed(data)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/terminal/vt100_input.py", line 398, in feed
    self._input_parser.send(c)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/terminal/vt100_input.py", line 307, in _input_parser_generator
    self._call_handler(match, prefix)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/terminal/vt100_input.py", line 340, in _call_handler
    self.feed_key_callback(KeyPress(key, insert_text))
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/interface.py", line 1048, in feed_key
    cli.input_processor.process_keys()
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/key_binding/input_processor.py", line 219, in process_keys
    self._process_coroutine.send(key_press)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/key_binding/input_processor.py", line 176, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/key_binding/input_processor.py", line 247, in _call_handler
    handler.call(event)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/key_binding/registry.py", line 61, in call
    return self.handler(event)
  File "/home/hugo/anaconda2/envs/py36/lib/python3.6/site-packages/prompt_toolkit/key_binding/bindings/basic.py", line 280, in _
    mouse_event, x, y = map(int, data[:-1].split(';'))
ValueError: not enough values to unpack (expected 3, got 2)

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

In Output:

None

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

None!

Interestingly, with the python interpreter, it does throw an error but the execution within an ipython terminal (sent as a python command) works!
(indeed in a python terminal having spaces before text throws an IndentationError but not in iPython....)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions