[Python-Dev] Warning Framework (PEP 230)
Guido van Rossum
guido@python.org
Mon, 11 Dec 2000 11:53:37 -0500
> Some of my thoughts after reading the PEP and Paul/Guido's exchange.
>
> - A function in the warn module is better than one in the sys module.
> "from warnings import warn" is good enough to not warrant a
> built-in. I get the sense that the PEP description is behind
> Guido's currently implementation here.
Yes. I've updated the PEP to match the (2nd) implementation.
> - When PyErr_Warn() returns 1, does that mean a warning has been
> transmuted into an exception, or some other exception occurred
> during the setting of the warning? (I think I know, but the PEP
> could be clearer here).
I've clarified this now: it returns 1 in either case. You have to do
exception handling in either case. I'm not telling why -- you don't
need to know. The caller of PyErr_Warn() should not attempt to catch
the exception -- if that's your intent, you shouldn't be calling
PyErr_Warn(). And PyErr_Warn() is complicated enough that it has to
allow raising an exception.
> - It would be nice if lineno can be a range specification. Other
> matches are based on regexps -- think of this as a line number
> regexp.
Too much complexity already.
> - Why not do setupwarnings() in site.py?
See the PEP and the current implementation. The delayed-loading of
the warnings module means that we have to save the -W options as
sys.warnoptions. (This also makes them work when multiple
interpreters are used -- they all get the -W options.)
> - Regexp matching on messages should be case insensitive.
Good point! Done in my version of the code.
> - The second argument to sys.warn() or PyErr_Warn() can be any class,
> right?
Almost. It must be derived from __builtin__.Warning.
> If so, it's easy for me to have my own warning classes.
> What if I want to set up my own warnings filters? Maybe if `action'
> could be a callable as well as a string. Then in my IDE, I could
> set that to "mygui.popupWarningsDialog".
No, for that purpose you would override warnings.showwarning().
--Guido van Rossum (home page: http://www.python.org/~guido/)