[code-quality] Possible spurious Flake8 warning F823

Ian Cordasco graffatcolmingov at gmail.com
Thu Apr 2 23:31:35 CEST 2015


On Thu, Apr 2, 2015 at 4:04 PM, Dan Wandschneider <
daniel.wandschneider at schrodinger.com> wrote:

> All-
> It seems like when I have a function that does "del" on a global variable,
> flake complains that a local variable is referenced before assignment.  As
> far as I know, the following is valid code:
>
> server = None
>
> def stopServer():
>     global server
>     if server:
>         del server
>         server = None
>
> test.py:6:8: F823 local variable 'server' (defined in enclosing scope on
> line 1) referenced before assignment
>
> I'm using flake --version: 2.1.0 (pep8: 1.4.6, mccabe: 0.2.1, pyflakes:
> 0.7.3)
>
> I understand that the "del" statement is redundant, but I don't think that
> it is wrong, per se. Is this code actually incorrect? If not, is there a
> way to suppress this error message? I'm interested in figuring this out as
> part of an effort to convince a coworker to start using flake on his/her
> code.
>
> Thanks -
> Dan W.
>
> _______________________________________________
> code-quality mailing list
> code-quality at python.org
> https://mail.python.org/mailman/listinfo/code-quality
>
>
The versions you list there are kind of old. I believe pyflakes 0.8.1 is
out. Flake8 wraps pep8, mccabe, and pyflakes. The error code you're seeing
is actually generated by pyflakes. I don't think this is an actual error in
your code sample though. You should report this to pyflakes and see if
there's anything that can be done to mitigate this. In the meantime, you
can do the following:

flake8 --ignore=F823 test.py

And you can store that in a config file like tox.ini or setup.cfg. The docs
should explain how to do that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20150402/f99daddf/attachment.html>


More information about the code-quality mailing list