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 a new warnings.showwarnmsg() function taking a warnings.WarningMessage object #70755

Closed
vstinner opened this issue Mar 15, 2016 · 8 comments

Comments

@vstinner
Copy link
Member

BPO 26568
Nosy @vstinner, @seberg
PRs
  • bpo-30812: Fix test_warnings, restore _showwarnmsg #2504
  • [3.6] bpo-30812: Fix test_warnings, restore _showwarnmsg (#2504) #2507
  • Files
  • warnings_showmsg.patch
  • 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 = <Date 2018-09-19.23:13:07.080>
    created_at = <Date 2016-03-15.14:32:00.604>
    labels = []
    title = 'Add a new warnings.showwarnmsg() function taking a warnings.WarningMessage object'
    updated_at = <Date 2018-09-19.23:13:07.079>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-09-19.23:13:07.079>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-09-19.23:13:07.080>
    closer = 'vstinner'
    components = []
    creation = <Date 2016-03-15.14:32:00.604>
    creator = 'vstinner'
    dependencies = []
    files = ['42172']
    hgrepos = []
    issue_num = 26568
    keywords = ['patch']
    message_count = 8.0
    messages = ['261814', '261823', '262008', '262009', '262011', '278976', '297378', '297381']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'THRlWiTi', 'python-dev', 'seberg']
    pr_nums = ['2504', '2507']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue26568'
    versions = ['Python 3.6']

    @vstinner
    Copy link
    Member Author

    Currently, the warnings.showformat() function take between 4 and 6 parameters and it's not possible to add new parameters.

    warnings.showformat() calls warnings.formatwarnings() with 5 parameters. Again, it's not easy to pass new parameters.

    I would like to add a new "source" parameter for ResourceWarning: see issue bpo-26567 "ResourceWarning: Use tracemalloc to display the traceback where an object was allocated when a ResourceWarning is emitted".

    To make warnings extensible, I propose to:

    • Add new showmsg() and formatmsg() functions to the warnings module, these functions take a warnings.WarningMessage instance
    • The _warnings module calls warnings.showmsg() rather than warnings.showwarning()
    • For backward compatibility, warnings.showmsg() calls warnings.showwarning() if warnings.showwarning() was replaced. Same for warnings.formatmsg(): call warnings.formatwarning() if replaced.

    Attached patch implements these changes.

    With these changes, the warnings looks a little bit more like the logging module and its logging.LogRecord class.

    The patch is incomplete, it doesn't add much tests yet and it doesn't touch the documentation. I would prefer to get the new API (and the whole idea) approved before going too far.

    Note: If warnings.showwarning is deleted ("del warnings.showwarning"), showmsg() uses its own implementation. Same for formatmsg().

    @vstinner
    Copy link
    Member Author

    I'm not sure about the method names showmsg() and formatmsg().

    Maybe: showwarnmsg() and formatwarnmsg()?

    First I used warnings.show() and warnings.format(), but "format()" is already the name of a builtin function.

    By the way, I would prefer to use underscore between names, like show_msg() or show_warn_msg(). But I don't know if it's ok to use a different naming scheme in an existing module :-/

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 19, 2016

    New changeset 79888b970cc4 by Victor Stinner in branch 'default':
    Add _showwarnmsg() and _formatwarnmsg() to warnings
    https://hg.python.org/cpython/rev/79888b970cc4

    @vstinner
    Copy link
    Member Author

    I pushed a change which adds a private _showwarnmsg(), but I'm still interested to make this new function public!

    I pushed the change to unblock the issue bpo-26567.

    @vstinner vstinner changed the title Add a new warnings.showmsg() function taking a warnings.WarningMessage object Add a new warnings.showwarnmsg() function taking a warnings.WarningMessage object Mar 19, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 19, 2016

    New changeset 9c92352324e8 by Victor Stinner in branch 'default':
    Fix test_logging
    https://hg.python.org/cpython/rev/9c92352324e8

    @seberg
    Copy link
    Mannequin

    seberg mannequin commented Oct 19, 2016

    To make warning testing saner, in numpy we added basically my own version of catch_warnings on steroids, which needed/will need changing because of this.

    Unless I missed it somewhere, this change should maybe put into the release notes to warn make it a bit easier to track down what is going on.

    @vstinner
    Copy link
    Member Author

    New changeset 7eebeb8 by Victor Stinner in branch 'master':
    bpo-30812: Fix test_warnings, restore _showwarnmsg (bpo-2504)
    7eebeb8

    @vstinner
    Copy link
    Member Author

    New changeset d0aac5d by Victor Stinner in branch '3.6':
    bpo-30812: Fix test_warnings, restore _showwarnmsg (bpo-2504) (bpo-2507)
    d0aac5d

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant