Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--exclude option doesn't work on some cases #48

Closed
AndreMiras opened this issue Jan 18, 2012 · 1 comment
Closed

--exclude option doesn't work on some cases #48

AndreMiras opened this issue Jan 18, 2012 · 1 comment

Comments

@AndreMiras
Copy link

Hi,
We've integrated your pep8 module in the unit tests of our Django CMS application.
The module is very convenient but we've found a bug with the --exclude option on the version 0.6.1 of pep8.
It occurs when we try to exclude two dirs which are alphabetically next to each other.
This is because the dirs.remove(subdir) of the input_dir method is modifying the sequence being iterated.
This isn't safe as stated in the Python documentation:
http://docs.python.org/tutorial/controlflow.html#for-statements

This example illustrate the bug, where "dir2" doesn't get ignored like it should:

$ find . -type f
./dir1/invalid.py
./dir2/invalid.py
$ pep8  .
./dir1/invalid.py:1:1: W391 blank line at end of file
./dir1/invalid.py:1:1: W293 blank line contains whitespace
$ pep8 --exclude dir1,dir2 .
./dir2/invalid.py:1:1: W391 blank line at end of file
./dir2/invalid.py:1:1: W293 blank line contains whitespace
$

Making a slice copy of the entire list as suggested in the above documentation works as a patch.

--- pep8.py     2012-01-19 00:23:57.790219545 +0100
+++ pep8.py.new 2012-01-19 00:25:30.094222777 +0100
@@ -1041,7 +1041,7 @@
             message('directory ' + root)
         options.counters['directories'] += 1
         dirs.sort()
-        for subdir in dirs:
+        for subdir in dirs[:]:
             if excluded(subdir):
                 dirs.remove(subdir)
         files.sort()

After applying the patch both dir1 and dir2 get ignored as expected:

$ pep8 --exclude dir1,dir2 .
$
@florentx
Copy link
Contributor

Fixed in 0.7.0.

@florentx florentx closed this as completed Apr 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants