Skip to content

Add no_traceback argument to :okexcept: option of ipython sphinx directive - #13751

Closed
StefRe wants to merge 2 commits into
ipython:mainfrom
StefRe:no_traceback
Closed

StefRe wants to merge 2 commits into
ipython:mainfrom
StefRe:no_traceback

Conversation

@StefRe

@StefRe StefRe commented Sep 8, 2022 •

Copy link
Copy Markdown
  • add optional no_traceback argument to :ok_except: which prevents the (sometimes long) traceback from being printed, default is no argument, i.e. traceback is printed
  • enable @okexcept pseudodecorator so that it can be applied to individual instructions instead of the whole block
  • adjust IPythonConsoleLexer so that it formats exceptions without preceding traceback as usual, add tests for this
  • apply darker to this commit
  • document the new argument

See also #8686, pandas-dev/pandas#47846 and pandas-dev/pandas/#48394.
This demo shows a minimal example.

(TODO: describe @okexcept in https://matplotlib.org/sampledoc/ipython_directive.html if this PR is goes in)
Edit 16.09.22: no need to update sampledoc as Matplotlib decided not to publish or maintain this document anymore, see matplotlib/sampledoc#26 (comment)

StefRe added a commit to StefRe/pandas that referenced this pull request Nov 26, 2022
- use local modified ipython_directive to add optional no_traceback
  argument to :ok_except: which prevents the (sometimes long) traceback
  from being printed (default is no argument, i.e. the traceback is
  printed) and enable the @okexcept pseudodecorator so that it can be
  applied to individual instructions instead of the whole block
- use local modified ipython_console_highlighting to enable syntax
  highlighting of exceptions without a traceback
- fix pylint warnings for ipython_directive.py and simplify
  "".join(["."] * x) to "." * x

The "# noqa: E999" after "@okexcept no_traceback" is necessary to
prevent flake8-rst from complaining about syntax errors as it
interprets the pseudodecorator as a real python decorator.

Items 1 and 2 can be reverted if github.com/ipython/ipython/pull/13751
gets merged upstream.
StefRe added a commit to StefRe/pandas that referenced this pull request Nov 27, 2022
- use local modified ipython_directive to add optional no_traceback
  argument to :ok_except: which prevents the (sometimes long) traceback
  from being printed (default is no argument, i.e. the traceback is
  printed) and enable the @okexcept pseudodecorator so that it can be
  applied to individual instructions instead of the whole block
- use local modified ipython_console_highlighting to enable syntax
  highlighting of exceptions without a traceback
- fix pylint warnings for ipython_directive.py and simplify
  "".join(["."] * x) to "." * x

The "# noqa: E999" after "@okexcept no_traceback" is necessary to
prevent flake8-rst from complaining about syntax errors as it
interprets the pseudodecorator as a real python decorator.

In ipython_directive.py:1106, pylint complains about access to
self.content before its definition although it is defined in the base
class. That's why I added "# pylint: disable=access-member-before-definition"
to make the pre-commit hook pass.

Items 1 and 2 can be reverted if github.com/ipython/ipython/pull/13751
gets merged upstream.
StefRe added a commit to StefRe/pandas that referenced this pull request Nov 27, 2022
- use local modified ipython_directive to add optional no_traceback
  argument to :ok_except: which prevents the (sometimes long) traceback
  from being printed (default is no argument, i.e. the traceback is
  printed) and enable the @okexcept pseudodecorator so that it can be
  applied to individual instructions instead of the whole block
- use local modified ipython_console_highlighting to enable syntax
  highlighting of exceptions without a traceback
- fix pylint warnings for ipython_directive.py and simplify
  "".join(["."] * x) to "." * x

The "# noqa: E999" after "@okexcept no_traceback" is necessary to
prevent flake8-rst from complaining about syntax errors as it
interprets the pseudodecorator as a real python decorator.

In ipython_directive.py:1106, pylint complains about access to
self.content before its definition although it is defined in the base
class. That's why I added "# pylint: disable=access-member-before-definition"
to make the pre-commit hook pass.

Items 1 and 2 can be reverted if github.com/ipython/ipython/pull/13751
gets merged upstream.
@datapythonista

Copy link
Copy Markdown

@Carreau any comment on this? In pandas (and I guess other projects) we've got some very long traceback in our documentation, that it'd be very nice to reduce. It'd be great if you could have a quick look here and let us know if you are happy with this approach, or what would you suggest. Thank you!

@Carreau

Carreau commented Jan 5, 2023

Copy link
Copy Markdown
Member

No objections in principle, I just have been struggling to find time to maintain IPython and review PRs.

StefRe added 2 commits January 5, 2023 10:01
…ctive

- add optional no_traceback argument to :ok_except: which prevents the
  (sometimes long) traceback from being printed, default is no argument,
  i.e. traceback is printed
- enable @okexcept pseudodecorator so that it can be applied to individual
  instructions instead of the whole block
- adjust IPythonConsoleLexer so that it formats exceptions without
  preceding traceback as usual, add tests for this
- apply darker to this commit
- document the new argument
@datapythonista

Copy link
Copy Markdown

No objections in principle, I just have been struggling to find time to maintain IPython and review PRs.

Totally understandable. Let me know if we can be of help. I'm not familiar with ipython code, but had a look at the PR, and changes make sense to me. Thanks!

@Carreau

Carreau commented Feb 23, 2025

Copy link
Copy Markdown
Member

Closing old stale PRs, sorry if this was not addressed, but this has been a few years, so there are few chances of someone actually pushing this through.

Feel free to resubmit if you feel this has a chance to be revived.

@Carreau Carreau closed this Feb 23, 2025
@Carreau Carreau added this to the no action milestone Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants