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

Nikolaus Rath Nikolaus at rath.org
Tue Feb 10 22:51:06 CET 2015


Eduard Bondarenko <eduardbpy-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> writes:
> Well, Perl also dynamic language, but except the usage of the additional
> analyser tools he provides 'use warning' directive and many Perl's
> developers use this feature.
>
> Why you do not want to add such feature in Python ?

One reason would be because it doesn't exist in Perl either:

$ cat test.pl 
use warnings;
$foo = <STDIN>;
if($foo eq "bar") {
    print("hello");
} else {
   print(undefined_variable)
}

$ perl test.pl 
Name "main::undefined_variable" used only once: possible typo at test.pl line 7.
foo
print() on unopened filehandle undefined_variable at test.pl line 6, <STDIN> line 1.


Note that you only get the warning about the undefined variable when the
code actually enters that branch.

You are getting a warning at compile time because you used the variable
only once, but I don't think that's what you'd like to add to Python. Or
is it?

Best,
-Nikolaus


-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-ideas mailing list