[Python-Dev] Warning Framework (PEP 230)

Guido van Rossum guido@python.org
Mon, 11 Dec 2000 20:21:41 -0500

> > 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!
> Do the following:
> pywarn.h or pyerrors.h:
> #define PyWARN_DEPRECATION "DeprecationWarning"
>      ...
>      if (PyErr_Warn(PyWARN_DEPRECATION,
>  		   "the strop module is deprecated"))
>              return NULL;
> The PyErr_Warn would then use the string to dynamically look up / bind to
> the correct value from the warnings module. By using the symbolic constant,
> you will catch typos in the C code (e.g. if people passed raw strings, then
> a typo won't be found until runtime; using symbols will catch the problem at
> compile time).
> The above strategy will allow for fully-delayed loading, and for all the
> warnings to be located in the "warnings" module.

Yeah, that would be a possibility, if it was deemed evil that the
warnings appear in __builtin__.  I don't see what's so evil about

(There's also the problem that the C code must be able to create new
warning categories, as long as they are derived from the Warning base
class.  Your approach above doesn't support this.  I'm sure you can
figure a way around that too.  But I prefer to hear why you think it's
needed first.)

--Guido van Rossum (home page: http://www.python.org/~guido/)