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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

StefRe
Copy link

@StefRe StefRe commented Sep 8, 2022

  • 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

@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
Copy link
Member

Carreau commented Jan 5, 2023

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

…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
Matplotlib decided to not publish this document anymore on their site,
see matplotlib/sampledoc#26 (comment)
@datapythonista
Copy link

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!

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