This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2016-03-15.14:32:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458052320.63.0.791464551893.issue26568@psf.upfronthosting.co.za>
In-reply-to
Content
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 #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().
History
Date User Action Args
2016-03-15 14:32:00vstinnersetrecipients: + vstinner
2016-03-15 14:32:00vstinnersetmessageid: <1458052320.63.0.791464551893.issue26568@psf.upfronthosting.co.za>
2016-03-15 14:32:00vstinnerlinkissue26568 messages
2016-03-15 14:32:00vstinnercreate