mne-python: Tab completion crashes IPython

Describe the bug

When using mne in IPython, pressing tab for tab-completion often (but not always) causes IPython to crash. This doesn’t happen when using objects that are not from mne-python.

Steps to reproduce

In IPython, execute the following code:

import mne
import os
from mne.datasets import multimodal

fname_raw = os.path.join(multimodal.data_path(), 'multimodal_raw.fif')
raw = mne.io.read_raw_fif(fname_raw)
cond = raw.acqparser.get_condition(raw, 'Auditory right')
epochs = mne.Epochs(raw, **cond)

Then type epochs.in and press tab.

Expected results

The list of tab-completion possibilities appears, or it autocompletes to epochs.info.

Actual results

IPython hangs for several seconds, then crashes. (Sometimes it works correctly.)

In [4]: epochs.in                                                                                                      
Traceback (most recent call last):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/cache.py", line 109, in wrapper
    return dct[key]
KeyError: ((), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/cache.py", line 109, in wrapper
    return dct[key]
KeyError: ((), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/__main__.py", line 14, in <module>
    start_ipython()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/__init__.py", line 126, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/traitlets/config/application.py", line 664, in launch_instance
    app.start()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/ipapp.py", line 356, in start
    self.shell.mainloop()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 558, in mainloop
    self.interact()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 541, in interact
    code = self.prompt_for_code()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 469, in prompt_for_code
    **self._extra_prompt_options())
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 997, in prompt
    return self.app.run()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 810, in run
    return loop.run_until_complete(self.run_async(pre_run=pre_run))
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/asyncio/base_events.py", line 583, in run_until_complete
    return future.result()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 777, in run_async
    return await _run_async2()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 765, in _run_async2
    await self.cancel_and_wait_for_background_tasks()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 862, in cancel_and_wait_for_background_tasks
    await task
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1854, in new_coroutine
    await coroutine(*a, **kw)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1684, in async_completer
    document, complete_event
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 270, in get_completions_async
    document, complete_event
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 196, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/ptutils.py", line 90, in get_completions
    yield from self._get_completions(body, offset, cursor_position, self.ipy_completer)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/terminal/ptutils.py", line 100, in _get_completions
    for c in completions:
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/core/completer.py", line 438, in _deduplicate_completions
    completions = list(completions)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/core/completer.py", line 1815, in completions
    for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/core/completer.py", line 1872, in _completions
    signature = _make_signature(jm)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/IPython/core/completer.py", line 989, in _make_signature
    return '(%s)'% ', '.join([f for f in (_formatparamchildren(p) for p in completion.params) if f])
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/cache.py", line 111, in wrapper
    result = method(self, *args, **kwargs)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/api/classes.py", line 428, in params
    for signature in self._get_signatures():
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/api/classes.py", line 505, in _get_signatures
    return [sig for name in names for sig in name.infer().get_signatures()]
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/api/classes.py", line 505, in <listcomp>
    return [sig for name in names for sig in name.infer().get_signatures()]
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/cache.py", line 111, in wrapper
    result = method(self, *args, **kwargs)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/compiled/mixed.py", line 124, in infer
    tree_values = tree_value.py__getattribute__(self.string_name)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/base_value.py", line 88, in py__getattribute__
    names = self.goto(name_or_str, name_context, analysis_errors)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/base_value.py", line 77, in goto
    names = finder.filter_name(filters, name_or_str)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/finder.py", line 35, in filter_name
    for filter in filters:
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/base_value.py", line 63, in _get_value_filters
    for f in self.get_filters(origin_scope=origin_scope):
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/value/instance.py", line 176, in get_filters
    class_value = self.get_annotated_class_object()
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/value/instance.py", line 350, in get_annotated_class_object
    return self._get_annotated_class_object() or self.class_value
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/cache.py", line 43, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/value/instance.py", line 339, in _get_annotated_class_object
    all_annotations = py__annotations__(signature.value.tree_node)
  File "/home/local/ADF/brookshg/anaconda3/envs/mne/lib/python3.7/site-packages/jedi/inference/gradual/annotation.py", line 189, in py__annotations__
    for function_param in funcdef.get_params():
AttributeError: 'Class' object has no attribute 'get_params'

If you suspect this is an IPython 7.12.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

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

Then it exits IPython and returns you to the login prompt.

Additional information

Platform:      Linux-4.15.0-76-generic-x86_64-with-debian-buster-sid
Python:        3.7.6 (default, Jan  8 2020, 19:59:22)  [GCC 7.3.0]
Executable:    /home/local/ADF/brookshg/anaconda3/envs/mne/bin/python
CPU:           x86_64: 4 cores
Memory:        39.1 GB

mne:           0.19.2
numpy:         1.18.1 {blas=mkl_rt, lapack=mkl_rt}
scipy:         1.4.1
matplotlib:    3.1.3 {backend=Qt5Agg}

sklearn:       0.22.1
numba:         0.48.0
nibabel:       3.0.1
cupy:          Not found
pandas:        1.0.0
dipy:          1.1.1
mayavi:        4.7.1 {qt_api=pyqt5, PyQt5=5.9.2}
pyvista:       0.23.1
vtk:           8.1.2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Thanks – good to know! It looks like setting IPython to use a different autocompleter fixes the problem. In case anyone else runs into this problem, here’s the solution: %config IPCompleter.use_jedi = False

a PR in jedi you shall send 😃

If you actually want to make the change in this comment permanent rather than having to type it every time you use the IPython repl.

Locate your ipython profile ($(ipython locate)/profile_default), and find the ipython_config.py file. Inside that file should be a line that looks like:

# c.Completer.use_jedi = True

Change that line to:

c.Completer.use_jedi = False