F811 incorrectly triggered

Bug #1297161 reported by Ihar Hrachyshka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
Fix Released
Low
Unassigned

Bug Description

When doing work for oslo.messaging project, I've found behaviour that seems like a bug. You can find the code that triggered it at: https://github.com/booxter/oslo.messaging/tree/self-config-with-fixture

When I run 'tox -e pep8' for the project with my patch applied (HEAD of the branch), I get the following:

[ihrachys@dhcp130-159 oslo.messaging]$ tox -e pep8
GLOB sdist-make: /home/ihrachys/proj/oslo.messaging/setup.py
pep8 inst-nodeps: /home/ihrachys/proj/oslo.messaging/.tox/dist/oslo.messaging-1.3.0a9.16.g7944d9d.zip
pep8 runtests: commands[0] | flake8
./tests/test_transport.py:147:1: F811 redefinition of unused 'transport' from line 24
        transport = messaging.get_transport(self.conf, **kwargs)
^
ERROR: InvocationError: '/home/ihrachys/proj/oslo.messaging/.tox/pep8/bin/flake8'
__________________________________________________________________ summary __________________________________________________________________
ERROR: pep8: commands failed

It seems that pyflakes checker parses the file from top to bottom, checking possible violations in sequence. So it locates this new local variable 'transport' definition, and checks thru the list of globals where there is an import with the same name. The problem occurs because transport import is not used in this file BEFORE the variable definition, while it's still used AFTER it, in other classes. I guess the check should be triggered only if the import in question is never used anywhere else in the file, no matter where the usage is located in regards to redefinition.

The code in question is in checker.py, addBinding():
...
                if (isinstance(existing, Importation)
                        and not existing.used
                        and (not isinstance(value, Importation) or
                             value.fullName == existing.fullName)
                        and reportRedef
                        and not self.differentForks(node, existing.source)):
...

Revision history for this message
Florent (florent.x) wrote :

Thank you for this report.

The patch is commited, and it will be in 0.8.1
https://github.com/pyflakes/pyflakes/commit/ffe926c282bf78737f8c34dff111ccbdab6c837b

Changed in pyflakes:
importance: Undecided → Low
milestone: none → 0.8.1
status: New → Fix Committed
Florent (florent.x)
Changed in pyflakes:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.