Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid exec call crashed IPython shell #12551

Open
doerwalter opened this issue Sep 11, 2020 · 3 comments
Open

Invalid exec call crashed IPython shell #12551

doerwalter opened this issue Sep 11, 2020 · 3 comments
Labels

Comments

@doerwalter
Copy link
Contributor

The following code snippet, when typed into an IPython shell, crashes IPython:

exec('a = 5', {}, [])

(What should have been the locals dictionary is a list instead).

The complete terminal looks like this:

$ ipython --quick
Python 3.8.5 (default, Jul 21 2020, 10:48:26)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: exec('a = 5', {}, [])
Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-c9e39d947ace>", line 1, in <module>
    exec('a = 5', {}, [])
  File "<string>", line 1, in <module>
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3337, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3434, in run_code
    self.showtraceback(running_compiled_code=True)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1335, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1192, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1152, in format_exception_as_a_whole
    frames = self.format_records(records, last_unique, recursion_repeat)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 891, in format_records
    if r[0].f_locals.get("__tracebackhide__", 0):
AttributeError: 'list' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'AttributeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2922, in _run_cell
    return runner(coro)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3145, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3356, in run_ast_nodes
    self.showtraceback()
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1335, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1210, in structured_traceback
    formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1152, in format_exception_as_a_whole
    frames = self.format_records(records, last_unique, recursion_repeat)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 891, in format_records
    if r[0].f_locals.get("__tracebackhide__", 0):
AttributeError: 'list' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'AttributeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/ipython-bad/bin/ipython", line 8, in <module>
    sys.exit(start_ipython())
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/__init__.py", line 126, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/traitlets/config/application.py", line 837, in launch_instance
    app.start()
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/terminal/ipapp.py", line 356, in start
    self.shell.mainloop()
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 564, in mainloop
    self.interact()
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 555, in interact
    self.run_cell(code, store_history=True)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2876, in run_cell
    result = self._run_cell(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2927, in _run_cell
    self.showtraceback(running_compiled_code=True)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1335, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1210, in structured_traceback
    formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1152, in format_exception_as_a_whole
    frames = self.format_records(records, last_unique, recursion_repeat)
  File "/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython/core/ultratb.py", line 891, in format_records
    if r[0].f_locals.get("__tracebackhide__", 0):
AttributeError: 'list' object has no attribute 'get'

If you suspect this is an IPython 7.18.1 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

python -c "import IPython; print(IPython.sys_info())" reports the following:

{'commit_hash': '95d2b79a2',
 'commit_source': 'installation',
 'default_encoding': 'utf-8',
 'ipython_path': '/Users/walter/pyvenvs/ipython-bad/lib/python3.8/site-packages/IPython',
 'ipython_version': '7.18.1',
 'os_name': 'posix',
 'platform': 'macOS-10.15.6-x86_64-i386-64bit',
 'sys_executable': '/Users/walter/pyvenvs/ipython-bad/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '3.8.5 (default, Jul 21 2020, 10:48:26) \n'
                '[Clang 11.0.3 (clang-1103.0.32.62)]'}
@doerwalter
Copy link
Contributor Author

This still happens with IPython 7.19.0.

@Carreau Carreau added the bug label Dec 14, 2020
@doerwalter
Copy link
Contributor Author

This still happens with IPython 8.0:

Python 3.10.1 (main, Dec  6 2021, 22:25:40) [Clang 13.0.0 (clang-1300.0.29.3)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.0 -- An enhanced Interactive Python. Type '?' for help.
🐍 — 1 — ❯ exec("a = 5", {}, [])
Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-2c7e4d2842c6>", line 1, in <module>
    exec("a = 5", {}, [])
  File "<string>", line 1, in <module>
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1934, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3191, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3268, in run_code
    self.showtraceback(running_compiled_code=True)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1936, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1105, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 999, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 852, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 793, in format_exception_as_a_whole
    if r.frame.f_locals.get("__tracebackhide__", 0) and i != lastrecord:
AttributeError: 'list' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1934, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'AttributeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2814, in _run_cell
    return runner(coro)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner
    coro.send(None)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3012, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3210, in run_ast_nodes
    self.showtraceback()
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1936, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1105, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 999, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 871, in structured_traceback
    formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 793, in format_exception_as_a_whole
    if r.frame.f_locals.get("__tracebackhide__", 0) and i != lastrecord:
AttributeError: 'list' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1934, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'AttributeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/bin/ipython3", line 8, in <module>
    sys.exit(start_ipython())
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/__init__.py", line 119, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/traitlets/config/application.py", line 846, in launch_instance
    app.start()
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 316, in start
    self.shell.mainloop()
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 611, in mainloop
    self.interact()
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 604, in interact
    self.run_cell(code, store_history=True)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2768, in run_cell
    result = self._run_cell(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2819, in _run_cell
    self.showtraceback(running_compiled_code=True)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1936, in showtraceback
    stb = self.InteractiveTB.structured_traceback(etype,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1105, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 999, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 871, in structured_traceback
    formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 793, in format_exception_as_a_whole
    if r.frame.f_locals.get("__tracebackhide__", 0) and i != lastrecord:
AttributeError: 'list' object has no attribute 'get'

If you suspect this is an IPython 8.0.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

@doerwalter
Copy link
Contributor Author

This seems to be fixed somewhat now with IPython 8.2.0. At least IPython no longer crashes:

Python 3.10.2 (main, Feb  2 2022, 06:19:27) [Clang 13.0.0 (clang-1300.0.29.3)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.
🐍 — 1 — 12:02:39.252315 ❯ exec('a = 5', {}, [])
Unexpected exception formatting exception. Falling back to standard exception
Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3369, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-c9e39d947ace>", line 1, in <cell line: 1>
    exec('a = 5', {}, [])
  File "<string>", line 1, in <module>
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 1982, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1118, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1012, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 865, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/IPython/core/ultratb.py", line 807, in format_exception_as_a_whole
    if r.frame.f_locals.get("__tracebackhide__", 0) and i != lastrecord:
AttributeError: 'list' object has no attribute 'get'
🐍 — 2 — 12:02:43.568381 ❯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants