[Python-ideas] Add 'use warnings' directive, like in Perl (original) (raw)
Eduard Bondarenko eduardbpy at gmail.com
Wed Feb 11 11:09:10 CET 2015
- Previous message: [Python-ideas] Add 'use warnings' directive, like in Perl
- Next message: [Python-ideas] Allow "assigning" to Ellipse to discard values.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello Dennis,
I know that, actually I mean the simple version of Perl's 'use warnings' directive. I do not mean to show warnings like " "isn't numeric" " in the code below or something like this.
my $a = "2:" + 3;
And roughly speaking, I mentioned Perl's directive to more clearly show what I mean.
About your reference. If I correctly understood provided material this is runtime warnings and absolutely not the same what I mean.
2015-02-11 11:03 GMT+02:00 Dennis Kaarsemaker <dennis at kaarsemaker.net>:
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 = rawinput("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 = rawinput("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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150211/3e992687/attachment.html>
- Previous message: [Python-ideas] Add 'use warnings' directive, like in Perl
- Next message: [Python-ideas] Allow "assigning" to Ellipse to discard values.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]