-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Comments
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:
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(). |
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 :-/ |
New changeset 79888b970cc4 by Victor Stinner in branch 'default': |
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. |
New changeset 9c92352324e8 by Victor Stinner in branch 'default': |
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. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: