Title: Add "ignore_modules" option to TracebackException.format()
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ncoghlan, pitrou, rbcollins, vaultah
Priority: normal Keywords:

Created on 2017-08-29 07:45 by ncoghlan, last changed 2017-11-09 23:07 by vaultah.

Pull Requests
URL Status Linked Edit
PR 3231 open vaultah, 2017-08-29 09:18
Messages (5)
msg300974 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-08-29 07:45
This is a proposed traceback module enhancement deriving from the "python -m" traceback verbosity discussion in issue 16217.

Specifically, I'm thinking a good way of cleaning up those tracebacks would be to use `TracebackException.format()` to get the formatted exception output, but designate particular modules to be *skipped* during the iteration (specifically `runpy`, `_frozen_importlib`, `importlib`).

I'm filing this as a separate issue so the discussion of the public API for the capability in the traceback module can be separated from the discussion of applying that API in runpy.
msg301791 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-09-09 20:32
I think a more general facility to strip unwanted frames from traceback objects would be useful for more people (including importlib, I think).  i.e. actually mutate the traceback object, not remove the unwanted frames when printing (since it only works if you're the one doing the printing).

(note mutating a traceback object is very easy in C, it's just not possible in pure Python, except perhaps with nasty ctypes hacks)

Also, the `ignore_modules` would be more powerful as a generic `filter` callback, I think.
msg302892 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-09-24 22:51
Yes, a public built-in facility to modify a traceback would certainly be useful, although there should be a standard way to "hide" unwanted frames without mutating the traceback, too, and the traceback module seems a perfect place to add it.

I have no objections to the `filter` argument, though filtering out frames based on modules to me feels by far more common a task than anything else `filter` would be capable of.

I can update the PR if there's a consensus that `filter` is favored over `ignore_modules`.
msg304921 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-10-24 15:54
Ping. (this issue needs a decision on ignore_modules vs filter callback, and/or patch review)
msg305996 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-11-09 23:07
I only recently realized that trace.Trace accepts two similar arguments, namely ignoremods and ignoredirs. Should we try to make the API and implementation of the functionality proposed here conform to that of trace.Trace's ignoremods? Would Python-Ideas be a more appropriate place to discuss this?
Date User Action Args
2017-11-09 23:07:56vaultahsetmessages: + msg305996
2017-10-24 15:54:13vaultahsetmessages: + msg304921
2017-09-24 22:51:35vaultahsetmessages: + msg302892
2017-09-09 20:32:57pitrousetnosy: + pitrou, brett.cannon
messages: + msg301791
2017-08-29 09:18:20vaultahsetpull_requests: + pull_request3274
2017-08-29 07:46:41ncoghlanlinkissue16217 dependencies
2017-08-29 07:45:45ncoghlancreate