[Python-Dev] Warning Framework (PEP 230)
Guido van Rossum
guido@python.org
Mon, 11 Dec 2000 19:39:31 -0500
> Since you must do "from warnings import warn" before using the warnings,
> then I think it makes sense to put the Warning classes into the warnings
> module. (e.g. why increase the size of the builtins?)
I don't particularly care whether the Warning category classes are
builtins, but I can't declare them in the warnings module. Typical
use from C is:
if (PyErr_Warn(PyExc_DeprecationWarning,
"the strop module is deprecated"))
return NULL;
PyErr_Warn() imports the warnings module on its first call. But the
value of PyExc_DeprecationWarning c.s. must be available *before* the
first call, so they can't be imported from the warnings module!
My first version imported warnings at the start of the program, but
this almost doubled the start-up time, hence the design where the
module is imported only when needed.
The most convenient place to create the Warning category classes is in
the _exceptions module; doing it the easiest way there means that they
are automatically exported to __builtin__. This doesn't bother me
enough to try and hide them.
--Guido van Rossum (home page: http://www.python.org/~guido/)