[Python-Dev] Catching "return" and "return expr" at compile time

Greg Ward gward@cnri.reston.va.us
Tue, 7 Sep 1999 12:13:27 -0400

On 07 September 1999, Guido van Rossum said:
> This is a valuable service!  Even though I'm sure that it will cause
> some pain for people who were used to this programming style...
> I'm not sure I like the fact that you can't turn it off --
> traditionally, Python has had a "no warnings" policy.  That has been
> diluted a bit (python -t prints warnings) but so far it has been the
> default.
> I'm wondering if we should introduce a general '-w' flag to turn on
> warnings like this (which would subsume -t)?  Or perhaps there should
> be a -W flag ("no warnings") and warnings should be the default?

Yes yes yes!  While adding "-w" is a long way from having a
comprehensive set of compile-time warnings in place, it at least means
that someone is *thinking* about it.

Also, I would suggest that there should be some standard internal
mechanism for reporting errors rather than just calling
'PySys_WriteStderr()'.  Something as simple as this would probably do
the trick:

   void Py_Warning (char *filename, int line, char *msg)
      if (on_a_platform_where_stderr_means_something)
         PySys_WriteStderr ("warning: file %s, line %d: %s",
                            filename, line, msg);

Well, you get the idea.  I make no claim that this is an appropriate
name for this function, nor do I have anything to say about where it
should live.  It should also be smart about unknown filename or line
number (eg. skip filename if filename == NULL, skip line number
if line == -1).

Oh, and of course we'll need to add a global variable $^W so that
programmers can turn run-time warnings on and off as needed.  *duck*
Maybe sys.show_warnings? ;-)  (Of course, that's assuming a run-time
warning system in addition to the compile-time warnings of -t and Skip's

Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive                           voice: +1-703-620-8990
Reston, Virginia, USA  20191-5434                    fax: +1-703-620-0913