[Python-ideas] Add 'use warnings' directive, like in Perl

Eduard Bondarenko eduardbpy at gmail.com
Tue Feb 10 17:04:47 CET 2015


Hello group,

my name is Eduard. I came into the Python community with an idea to add
(implicitly or explicitly) 'use warnings' directive into the python's
programs.

I think that everyone who worked with Perl understand what I am talking
about. For the rest I will explain the idea.

Actually, this is my first experience for writing into the community like
this, so excuse me if you found some mistakes or oddities. Also I do not
know whether you are already talk about this topic..in any case - sorry.

So, imagine that you have a program:

#!/usr/bin/python

*word* = raw_input("Enter line : ")

if *word* == "hello":
  print ("You wrote \'hello\'")
else:
  if *world* == "buy": #Error! should be word not world
    print "Buy"
else:
  *iamnotfunction* #Also error

This script contains two errors. And in both cases we will know about it at
runtime. And the most worst thing is that you will not know about these
errors until someone enters anything other than the "hello" word..

Try and except blocks do not solve this problem. Within this approach we
also receive problem at runtime.

What I propose ? I propose to add 'use warnings' directive. This directive
will provide deeply verification. Like this:

#!/usr/bin/python

*use warnings*

*word* = raw_input("Enter line : ")

if *word* == "hello":
  print ("You wrote \'hello\'")
else:
  if *world* == "buy": #Error! should be word not world
    print "Buy"
else:
  *iamnotfunction* #Also error

Output:
Use of uninitialized value world in  eq (==) at test.py line ..
Useless use of a constant (iamnotfunction) in void context at test.py line
..

The user will see the output like this and the program will not start.


To my mind the good idea is to explicitly set this directive. If developer
does not want spend time for this checking, he can omit 'use warning'
directive. Also it will not corrupt the existing programs. And developers
will have a chance to add this line gradually.


Many thanks!

- Eduard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150210/b2666e90/attachment.html>


More information about the Python-ideas mailing list