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

Ian Cordasco graffatcolmingov at gmail.com
Tue Feb 10 17:26:41 CET 2015


Hi Eduard,

Welcome to Python!

On Tue, Feb 10, 2015 at 10:12 AM, Florian Bruhin <me at the-compiler.org> wrote:
> Hi,
>
> * Eduard Bondarenko <eduardbpy at gmail.com> [2015-02-10 18:04:47 +0200]:
>> What I propose ? I propose to add 'use warnings' directive. This directive
>> will provide deeply verification. Like this:
>
> It probably doesn't make sense to add something like this to CPython
> itself - but there are many third-party tools which do such kind of
> checks (and which I can recommend to use!), static analyzers/linters:
>
> https://pypi.python.org/pypi/pyflakes
> https://pypi.python.org/pypi/pep8
> https://pypi.python.org/pypi/flake8 (a wrapper around pyflakes/pep8)
> http://www.pylint.org/

So as a maintainer/contributor to three of those I agree. But they're
external dependencies which I sense is something you don't want.

The reality is that you can compile this code with some standard
library modules and they'll give you the feedback you want. If you
were to run this code you'd get a NameErrors for the first line where
you expect a warning and you would get a SyntaxError for the second
else statement after the first. pyflakes and flake8 turn those into
error codes for you. So really, python already comes with the warnings
on because doing

$ python test.py

Would first result in a SyntaxError (because of your else following
the first else) and then once that's been fixed, you'd get a
NameError.

Disclaimer: I didn't actually run the code so I may have the order of
errors wrong, but I think this is roughly correct.

Cheers,
Ian


More information about the Python-ideas mailing list