[Python-3000] Extending warnings for Py3K - any interest?
Andrew Clover
and-dev at doxdesk.com
Mon Nov 20 11:59:20 CET 2006
I've always felt slightly disappointed by the Python warnings interface.
It's great for managing language feature deprecation, but I've often
wanted something I could also use for recoverable errors in general.
I've written multiple application-specific mechanisms for allowing a
caller to customise handling of potentially recoverable conditions in
the past, so I think it's probably a fairly common use case, and maybe,
if others how found the same, worth standardising as an extension of the
existing Python warnings system.
Here's a first sketch of the sort of thing I'm thinking of:
http://doxdesk.com/file/software/py/v/warnings2-0.1.py
Features:
- warnings as instances with arbitrary properties, rather than being
limited to a string message;
- different severities with different default actions, so trivial
warnings can be ignored by default and things which are by default
errors can be recovered if a filter says so;
- option to store warning instances that occur for later handling;
- switchable warnings-handling contexts (like eg. the decimal module)
for temporary changes to filters;
- context manager helpers so you can say things like:
with ignoring(DeprecationWarning):
import oldmodule
with storing(InvalidDataWarning) as problems:
reghive.scanKeys()
for problem in problems: ...
Anyone agree/disagree with the idea of adding such functionality to
warnings, or what features are worthwhile?
--
And Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
More information about the Python-3000
mailing list