-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Don't show traceback for :okexcept: #48394
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
Conversation
7c88620
to
6695460
Compare
d70d6a6
to
4431375
Compare
Seems to work, the only thing I don't understand is why we don't get the color output for the exception class, see the created docs artifact: I made a minimal example and the error message gets nicely formatted according to the chosen theme (I also tested the example with sphinx 4.5.0 (used on CI) instead of 5.1.1 and with the Any thoughts on this @mroeschke? Would it be OK to have the error message without color formatting? |
Yeah I think it would be fine if there was no color to start. Could be addressed later |
I found the culprit: ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)') So this will need to be changed to something like this to work for exceptions without preceding traceback: import builtins
exceptions = [name for name, value in builtins.__dict__.items() if isinstance(value, type) and issubclass(value, Exception) and not issubclass(value, Warning)]
ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)|^(' + '|'.join(exceptions) + '): \S.*\n') |
Do you think this is something that can fixed upstream in iPython? |
Let's see if ipython/ipython#13751 gets merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @StefRe, really nice. lgtm, let's see if we can get the changes merged upstream
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
4431375
to
59794e9
Compare
Yes, still interested in it. Rebased onto current master. Waiting for ipython/ipython#13751 to be reviewed. |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Yes, still interested in it. Rebased onto current master. Waiting for ipython/ipython#13751 to be reviewed. |
08315f6
to
f7447e8
Compare
- 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.
f7447e8
to
73a2059
Compare
As the PR ipython/ipython#13751 to update the ipython_directive and ipython_console_highlighting in IPython doesn't seem to be merged or even reviewed anytime soon, I suggest using vendored versions of these directives. Is this OK with you? If so, my plan is to:
|
Since this PR is pending on ipython/ipython#13751, going to close this for now and we can reopen when that PR is accepted |
Draft to see if docs build on CI
no_traceback
argument to
:ok_except:
which prevents the (sometimes long) tracebackfrom being printed (default is no argument, i.e. the traceback is
printed) and enable the
@okexcept
pseudodecorator so that it can beapplied to individual instructions instead of the whole block
highlighting of exceptions without a traceback
"".join(["."] * x)
to"." * x
The
# noqa: E999
after@okexcept no_traceback
is necessary toprevent 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 baseclass. 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 ipython/ipython#13751
gets merged upstream.
Example of the new docs including correct syntax highlighting with the

no_traceback
option:doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.