[Python-ideas] Add 'use warnings' directive, like in Perl
Dennis Kaarsemaker
dennis at kaarsemaker.net
Wed Feb 11 10:03:11 CET 2015
Hi Eduard,
What you describe is not at all equivalent to 'use warnings' in perl.
'use warnings' is a directive to enable/disable all or certain warnings
perl code may emit. The equivalent of this exists in python:
https://docs.python.org/3.1/library/warnings.html
On di, 2015-02-10 at 18:04 +0200, Eduard Bondarenko 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/
--
Dennis Kaarsemaker
http://www.kaarsemaker.net
More information about the Python-ideas
mailing list