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

Ryan Hiebert ryan at ryanhiebert.com
Tue Feb 10 17:14:28 CET 2015


Linters are actually quite good at finding this kind of mistake, and are the accepted way to deal with such checks.

Flake8 is a popular one you may wish to check out:
https://pypi.python.org/pypi/flake8 <https://pypi.python.org/pypi/flake8>

Ryan

> On Feb 10, 2015, at 10:04 AM, Eduard Bondarenko <eduardbpy at gmail.com> wrote:
> 
> 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
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

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


More information about the Python-ideas mailing list