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 "ignore_modules" option to TracebackException.format() #75480

Open
ncoghlan opened this issue Aug 29, 2017 · 10 comments
Open

Add "ignore_modules" option to TracebackException.format() #75480

ncoghlan opened this issue Aug 29, 2017 · 10 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

BPO 31299
Nosy @brettcannon, @ncoghlan, @pitrou, @rbtcollins, @pablogsal, @iritkatriel
PRs
  • bpo-31299: Make it possible to filter out frames from tracebacks #26772
  • bpo-31299: make it possible to filter out frames from tracebacks #28067
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-08-29.07:45:45.416>
    labels = ['type-feature', 'library', '3.10']
    title = 'Add "ignore_modules" option to TracebackException.format()'
    updated_at = <Date 2021-08-31.20:42:18.563>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2021-08-31.20:42:18.563>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-08-29.07:45:45.416>
    creator = 'ncoghlan'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31299
    keywords = ['patch']
    message_count = 10.0
    messages = ['300974', '301791', '302892', '304921', '305996', '306762', '328137', '334399', '382694', '400777']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'pitrou', 'rbcollins', 'pablogsal', 'iritkatriel']
    pr_nums = ['26772', '28067']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31299'
    versions = ['Python 3.10']

    @ncoghlan
    Copy link
    Contributor Author

    This is a proposed traceback module enhancement deriving from the "python -m" traceback verbosity discussion in bpo-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.

    @ncoghlan ncoghlan added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 29, 2017
    @pitrou
    Copy link
    Member

    pitrou commented Sep 9, 2017

    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.

    @vaultah
    Copy link
    Mannequin

    vaultah mannequin commented Sep 24, 2017

    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.

    @vaultah
    Copy link
    Mannequin

    vaultah mannequin commented Oct 24, 2017

    Ping. (this issue needs a decision on ignore_modules vs filter callback, and/or patch review)

    @vaultah
    Copy link
    Mannequin

    vaultah mannequin commented Nov 9, 2017

    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?

    @pablogsal
    Copy link
    Member

    I have prepared a patch (attached) with a possible implementation of the C function that can filter traceback objects modifying the traceback chain. I can make a PR if the patch looks good enough to start iterating over it. In case an alternative implementation is needed I am more than happy to prepare another patch/PR.

    @vaultah
    Copy link
    Mannequin

    vaultah mannequin commented Oct 20, 2018

    I asked for some input on this issue in January (https://mail.python.org/pipermail/python-dev/2018-January/151590.html). Since then an important PR was merged (#4793), however it mutates the traceback object. Should there be a way to hide frames while keeping the original traceback object intact? If not, this issue should probably be closed. Otherwise I would appreciate a review of the PR.

    @vaultah
    Copy link
    Mannequin

    vaultah mannequin commented Jan 26, 2019

    It would seem no one is actually interested in this proposed enhancement. I'm closing my PR, since I'm not interested in resolving the file conflict. I'll probably submit a traceback-mutating patch to the bpo-16217. This issue can be closed.

    @iritkatriel
    Copy link
    Member

    In bpo-42247 the unit test framework uses limit as a hack to remove its own frame, and then the traceback module applies the limit to the chained exception as well.

    If the filter suggested here existed, unit test could use that instead of limit.

    @iritkatriel iritkatriel added 3.10 only security fixes and removed 3.7 (EOL) end of life labels Dec 7, 2020
    @iritkatriel
    Copy link
    Member

    New changeset 863154c by Irit Katriel in branch 'main':
    bpo-31299: make it possible to filter out frames from tracebacks (GH-28067)
    863154c

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants