Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
48.81k stars 1.71k forks source link

[BUG] IPython extension: add ipython cell line to traceback #2880

Open Paul-Aime opened 1 year ago

Paul-Aime commented 1 year ago

Description

When using the rich extension for IPython terminal (%load_ext rich), and when there is an error, I can't see the line from which the error arises, only its line number.

I often have pretty long cells and it's not easy to spot which line is causing the error since there is no lines numbers display in IPython cells.

The default traceback does show the cell line in addition to its line number.

Would it be possible to have the same with the nice traceback of the rich extension?

Code to reproduce

In [1]: import random
   ...:
   ...: random.choices([0, 1, 2, 3, 4], k=3, p=[0.1, 0.3, 0.1, 0.25, 0.25])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 3
      1 import random
----> 3 random.choices([0, 1, 2, 3, 4], k=3, p=[0.1, 0.3, 0.1, 0.25, 0.25])

TypeError: choices() got an unexpected keyword argument 'p'

In [2]: %load_ext rich

In [3]: import random
   ...:
   ...: random.choices([0, 1, 2, 3, 4], k=3, p=[0.1, 0.3, 0.1, 0.25, 0.25])
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:3                                                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: choices() got an unexpected keyword argument 'p'

Platform

Click to expand ``` ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 54 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = True │ │ is_jupyter = False │ │ is_terminal = True │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=213, height=54), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=213, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=54, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=213, height=54) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 213 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': 'xterm-kitty', │ │ 'COLORTERM': 'truecolor', │ │ 'CLICOLOR': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': None, │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Linux" ```
github-actions[bot] commented 1 year ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory