GithubHelp home page GithubHelp logo

pycqa / flake8 Goto Github PK

View Code? Open in Web Editor NEW
3.3K 38.0 298.0 3.57 MB

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.

Home Page: https://flake8.pycqa.org

License: Other

Python 100.00%
python python3 static-analysis static-code-analysis linter linter-flake8 stylelint styleguide style-guide flake8

flake8's Introduction

build status

pre-commit.ci status

Discord

Flake8

Flake8 is a wrapper around these tools:

  • PyFlakes
  • pycodestyle
  • Ned Batchelder's McCabe script

Flake8 runs all the tools by launching the single flake8 command. It displays the warnings in a per-file, merged output.

It also adds a few features:

  • files that contain this line are skipped:

    # flake8: noqa
  • lines that contain a # noqa comment at the end will not issue warnings.
  • you can ignore specific errors on a line with # noqa: <error>, e.g., # noqa: E234. Multiple codes can be given, separated by comma. The noqa token is case insensitive, the colon before the list of codes is required otherwise the part after noqa is ignored
  • Git and Mercurial hooks
  • extendable through flake8.extension and flake8.formatting entry points

Quickstart

See our quickstart documentation for how to install and get started with Flake8.

Frequently Asked Questions

Flake8 maintains an FAQ in its documentation.

Questions or Feedback

If you have questions you'd like to ask the developers, or feedback you'd like to provide, feel free to use the mailing list: [email protected]

We would love to hear from you. Additionally, if you have a feature you'd like to suggest, the mailing list would be the best place for it.

Maintenance

Flake8 was created by Tarek Ziadé and is currently maintained by anthony sottile and Ian Cordasco

flake8's People

Contributors

asottile avatar carljm avatar christianmlong avatar ericvw avatar florentx avatar geonu avatar isac322 avatar jasonamyers avatar jdufresne avatar jezdez avatar jfhc avatar jogo avatar kynan avatar lost-theory avatar megies avatar msabramo avatar mxr avatar peterjc avatar pre-commit-ci[bot] avatar pteichman avatar rkm avatar schlamar avatar scop avatar sigmavirus24 avatar tadaboody avatar tarekziade avatar tylerwince avatar viicos avatar xzise avatar ymdatta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flake8's Issues

Support ability to exclude/include files for doctest checking from config file only

In GitLab by @sigmavirus24 on Dec 15, 2014, 06:27

See https://mail.python.org/pipermail/code-quality/2014-December/000461.html for discussion.

In short we should support providing a way to exclude files from the doctest checks that we provide access to. I'm tempted to only implement one of the options (include or exclude) but that would break consistency in the tool so we'll have to implement both.

Currently, I like the options:

[flake8]
exclude_from_doctest = foo.py bar.py bogus.py
include_in_doctest = fiz.py buz.py quine.py

EXTRA_IGNORE (['.tox']) is being unioned into ignored error codes

In GitLab by @sigmavirus24 on Sep 28, 2014, 09:49

Originally reported by Andrew Sottile at https://bitbucket.org/tarek/issues


My assumption is this was actually intended to be unioned into exclude and is not actually doing what it expects to do. Deleting the union causes no tests to fail (however there aren't really any tests on this file).

Declaration: https://bitbucket.org/tarek/flake8/src/a209fb69350c572c9b2d7b4b09c7657be153be5e/flake8/main.py?at=default#cl-18

Code: https://bitbucket.org/tarek/flake8/src/a209fb69350c572c9b2d7b4b09c7657be153be5e/flake8/main.py?at=default#cl-61

Pinned dependencies

In GitLab by @doismellburning on Feb 9, 2015, 05:34

(I apologise for essentially filing a "my version pinning philosophy differs from yours" bug)

Part of my test suite involves "run flake8, fail the tests if any errors are generated". I believe this to be a relatively common scenario.

Right now, flake8 does not pin its dependencies. Over the weekend, pep8 version 1.6.0 was released, which added new checks. This meant my code, despite using a pinned version of flake8, went from "passing" to "not passing" with no internal changes.

I understand that I could, and perhaps should, pin everything - flake8 and all transient dependencies.

However, I propose that flake8 should pin its dependencies - it's effectively a standalone tool rather than a library designed for integration with other existing libraries; it should be enough to say "my code is clean under flake8==2.3.0", rather than needing to declare "this version of flake8 with this version of pep8 and this version of pyflakes and this version of mccabe".

flake8 does not respect "ignore" configuration

In GitLab by @Ayrx on Feb 23, 2015, 05:54

As documented, flake8 should respect the "ignore" field in a tox.ini config file. flake8 2.3.0 does not seem to do that.
Here is a minimal reproduction of the bug: https://github.com/Ayrx/tox-bug-repro. I would expect that flake8 passes without flagging the unused import here. However, I get the following results.

$ tox -e pep8
pep8 runtests: PYTHONHASHSEED='2632284098'
pep8 runtests: commands[0] | flake8 .
./test.py:1:1: F401 'sys' imported but unused
ERROR: InvocationError: '/home/ayrx/code/tox-bug-repro/.tox/pep8/bin/flake8 .'
___________________________________ summary ____________________________________
ERROR:   pep8: commands failed

$ flake8 .
./test.py:1:1: F401 'sys' imported but unused

Here are the packages installed in my virtualenv.

$ pip list
flake8 (2.3.0)
mccabe (0.3)
pep8 (1.6.2)
pip (6.0.8)
py (1.4.26)
pyflakes (0.8.1)
setuptools (12.2)
tox (1.8.1)
virtualenv (12.0.7)

Let me know if more information is needed.

Convert tags

In GitLab by @sigmavirus24 on Sep 21, 2014, 11:19

In the mercurial to git export, the tags were lost. We need to go back and identify the commits so we can properly add the equivalent git tags.

Jobs warning tests failing on Windows with Python < 3.4

In GitLab by @christianmlong on Mar 11, 2015, 18:42

Flake8 issues warnings when the --jobs option is used in an incompatible way (e.g. with the --diff option). The tests for this feature are in flake8/tests/test_warnings.py.

Under certain condition, the tests in test_warnings.py fail.


Tests pass

Linux - Ubuntu 14.10

2.6, 2.7, 3.2, 3.3, 3.4

Windows - 8.1

3.4


Tests fail

Windows - 8.1

2.7, 3.3


They fail because the warnings are not issued, or are not captured. However, when the tests in test_warnings.py are run alone, without the rest of the test suite, they pass. Using the nosetests --isolation option does not help.

The nature of the tests (patching stdin, stdout) and the pattern of failure (Windows, Python < 3.4) makes me think the failure might have something to do with PEP 446 "Make newly created file descriptors non-inheritable".


One proposed solution (PR coming soon) is to run the tests in test_warnings.py separately, in a separate line in the tox [testenv] stanza.


Tracebacks

======================================================================
FAIL: test_jobs_verbose (flake8.tests.test_warnings.IntegrationTestCaseWarnings)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 190, in test_jobs_verbose
    self.test_jobs(verbose=True)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 160, in test_jobs
    self._job_tester(2, verbose=verbose)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 157, in _job_tester
    self.verify_warnings(collected_warnings, expected_warings)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 88, in verify_warnings
    len(expected_warnings))
nose.proxy.AssertionError: 0 != 1
-------------------- >> begin captured stdout << ---------------------
local configuration: in C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8
checking C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py

--------------------- >> end captured stdout << ----------------------

======================================================================
FAIL: test_stdin_jobs_warning_verbose (flake8.tests.test_warnings.IntegrationTestCaseWarnings)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 196, in test_stdin_jobs_warning_verbose
    self.test_stdin_jobs_warning(verbose=True)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 186, in test_stdin_jobs_warning
    self.verify_warnings(collected_warnings, expected_warings)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_warnings.py", line 88, in verify_warnings
    len(expected_warnings))
nose.proxy.AssertionError: 1 != 2
-------------------- >> begin captured stdout << ---------------------
local configuration: in C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8
checking -

--------------------- >> end captured stdout << ----------------------

2.2.5: test failure: AttributeError: 'FinalizingSuiteWrapper' object has no attribute '_removed_tests'

In GitLab by @wiz on Jan 2, 2015, 16:30

On NetBSD with python-3.4.2 I see the following issue when running the tests:

running build_ext
test_get_parser (flake8.tests.test_engine.TestEngine) ... ok
test_get_python_version (flake8.tests.test_engine.TestEngine) ... ok
test_get_style_guide (flake8.tests.test_engine.TestEngine) ... ok
test_get_style_guide_kwargs (flake8.tests.test_engine.TestEngine) ... ok
test_register_extensions (flake8.tests.test_engine.TestEngine) ... ok
test_stdin_disables_jobs (flake8.tests.test_engine.TestEngine) ... ok
test_windows_disables_jobs (flake8.tests.test_engine.TestEngine) ... ok
Traceback (most recent call last):
  File "setup.py", line 74, in <module>
    test_suite='nose.collector',
  File "/usr/pkg/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/pkg/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/pkg/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/usr/pkg/lib/python3.4/site-packages/setuptools/command/test.py", line 142, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/usr/pkg/lib/python3.4/site-packages/setuptools/command/test.py", line 122, in with_project_on_sys_path
    func()
  File "/usr/pkg/lib/python3.4/site-packages/setuptools/command/test.py", line 163, in run_tests
    testRunner=self._resolve_as_ep(self.test_runner),
  File "/usr/pkg/lib/python3.4/unittest/main.py", line 93, in __init__
    self.runTests()
  File "/usr/pkg/lib/python3.4/unittest/main.py", line 244, in runTests
    self.result = testRunner.run(self.test)
  File "/usr/pkg/lib/python3.4/unittest/runner.py", line 168, in run
    test(result)
  File "/usr/pkg/lib/python3.4/unittest/suite.py", line 87, in __call__
    return self.run(*args, **kwds)
  File "/usr/pkg/lib/python3.4/unittest/suite.py", line 130, in run
    self._removeTestAtIndex(index)
  File "/usr/pkg/lib/python3.4/unittest/suite.py", line 83, in _removeTestAtIndex
    self._removed_tests += test.countTestCases()
  File "/usr/pkg/lib/python3.4/unittest/suite.py", line 41, in countTestCases
    cases = self._removed_tests
AttributeError: 'FinalizingSuiteWrapper' object has no attribute '_removed_tests'
*** Error code 1

Add ability to skip long comments

In GitLab by @harlowja on Jan 10, 2015, 20:12

If your code contains a long-documentation/comment such as one with a RST formatted table in it; this causes complaints about having to long of lines; but in certain cases with tables there is no easy way to make that satisfied; it'd be nice to have a way to ignore the long-line limits inside comments only. Thoughts?

options mucked up when run as setuptools command

In GitLab by @mforbes on Mar 8, 2015, 15:56

When including options in setup.cfg such as the following ignore

[flake8]
ignore = E225,E226,W293

running python setup.py flake8 fails. The reason is that the arguments are only partially digested by flake8, and then passed as a kwarg {'ignore': 'E225,E226,W293'} (from self.options_dict) to pep8's get_style_guide. The latter must expect that the ignore= argument is fully digested as a tuple ignore=('E225', 'E226', 'W293') as it does not digest further and simply pulls this apart options.ignore = ... tuple(options.ignore) to obtain the useless set of ignores ('E', '2', '2', '5', ',',.... (This code is the same in pre 1.6.0 versions and 1.6.2).

I believe this is just another incarnation of issue #4 for which the fix was specific to a single exclude option rather than addressing the general issue.

Please either completely digest the options, or somehow let pep8 do it instead (not sure how though). Actually, in retrospect, why are options like ignore specified in the [flake8] section rather than simply in the [pep8] section where both pep8 and flake8 could be configured together (for the pep8 related stuff)?

Flake8Command.run() raises SystemExit even on success.

In GitLab by @mforbes on Mar 8, 2015, 14:22

Even when successful, Flake8Command.run() will raise a SystemExit(0) exception, making it difficult to work with (my use-case was writing a custom test command that runs flake8, nose tests, etc.) Please consider ananlogous change to 236e0f0:

    if exit_code > 0:
        raise SystemExit(exit_code > 0)

[flake8] section in setup.cfg fails on numbers

In GitLab by @dsvensson on Jan 5, 2015, 14:01

I've tried copying the max-line-length example configuration from the documentation into my setup.cfg:

[flake8]
max-line-length = 160

But when running via python setup.py flake8 I get the following failure:

File "/.../.eggs/pep8-1.5.7-py3.4.egg/pep8.py", line 204, in maximum_line_length
if length > max_line_length and not noqa(line):
TypeError: unorderable types: int() > str()

So it looks like the max-line-length is picked up from setup.cfg as a string, at least in Python 3.4 (which my module depends on).

`exclude` setting doesn't work when passing full path

In GitLab by @arufuredosan on Jan 23, 2015, 13:10

On a setup.cfg file that has:

[flake8]
exclude = tests

And a project that has the following layout:

project/
    tests/
        test_foo.py

If on the project directory and I run:

flake8 .

Then the configuration will correctly kick in and tests will not be picked up.

However, if we run:

flake8 tests/test_foo.py

Then that file gets linted.

Although it is non-obvious why someone ignoring tests would pass the file that is actually in the ignored
directory, it is how the khuno.vim plugin works. When on a given file (like test_foo.py) the plugin
will call flake8 with the full path to report back the linting to the editor.

Reference issue on khuno tracker: alfredodeza/khuno.vim#20

flake8 configuration file on Mac OS X

In GitLab by @hongxuchen on Feb 11, 2015, 23:51

flake8's configuration file ~/.config/flake8 does not work on my Mac OS X although it works on another Debian system. The results of flake8 --version are as follows:

2.2.3 (pep8: 1.5.7, pyflakes: 0.8.1, mccabe: 0.2.1, naming: 0.2.2) CPython 2.7.8 on Linux
2.3.0 (pep8: 1.6.1, pyflakes: 0.8.1, mccabe: 0.3, naming: 0.2.2) CPython 2.7.6 on Darwin

A similar issue was found on stackoverflow.

As I don't like to specify the extra args each time for different IDEs, is there such a default config file location for Mac OS X?

Version conflict with most recent pep8 release.

In GitLab by @peter-danecek on Mar 17, 2015, 12:37

The requirement limits of the current release 2.4.0 of flake8 conflict with the current release of pep8, which is at 1.6.2 and installed with Macports in my case.

    raise VersionConflict(dist, req).with_context(dependent_req)
VersionConflict: (pep8 1.6.2 (/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages), Requirement.parse('pep8<1.6,>=1.5.7'))

Is there a real need for this restriction and could it be removed soon?

Release 2.2.4

In GitLab by @terite on Oct 8, 2014, 08:53

I would really appreciate a 2.2.4 release to address the multiprocessing fixes that are in master but not yet released.

Also, The "Home Page" of the pypi page still points to the bitbucket repository.

Order is nondeterministic with multiprocessing and piped output

In GitLab by @quentinp on Nov 17, 2014, 03:24

Steps to reproduce:

  • In a directory, create two files a.py and b.py with an error each (eg. both containing a=1).
  • From the directory, run flake8 -j2 . | tee multiple times (for i in `seq 1 10` ; do flake8 -j2 . | tee; echo; done can be useful).

Expected result:

The order is always the same, eg. a.py, then b.py. This is the case with pep8 and flake8 -j1, or when the output is not piped. (By the way, I originally hit the error with watch, not tee).

Actual result:

The order is nondeterministic: sometimes a.py is first, sometimes b.py is first instead.

return statement in class body causes a gnarly traceback

In GitLab by @lvh on Jan 21, 2015, 17:38

I was continuously running flake8 on my project to clean lint. Suddenly, flake8 starts crashing:

~/P/r/otter: flake8 | grep cass                                                                                                                                                                     17:36:35
Process Process-3:
Traceback (most recent call last):
  File "/Users/lvh/.pyenv/versions/2.7.8/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/Users/lvh/.pyenv/versions/2.7.8/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/flake8/reporter.py", line 74, in process_main
    self._process_main()
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/flake8/reporter.py", line 50, in _process_main
    self.input_file(filename)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/flake8/engine.py", line 92, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pep8.py", line 1412, in check_all
    self.check_ast()
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pep8.py", line 1358, in check_ast
    checker = cls(tree, self.filename)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/flake8/_pyflakes.py", line 43, in __init__
    withDoctest=self.withDoctest)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 294, in __init__
    self.handleChildren(tree)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 547, in handleChildren
    self.handleNode(node, tree)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 589, in handleNode
    handler(node)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 812, in CLASSDEF
    self.handleNode(stmt, node)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 589, in handleNode
    handler(node)
  File "/Users/lvh/.pyenv/versions/otter/lib/python2.7/site-packages/pyflakes/checker.py", line 696, in RETURN
    if node.value and not self.scope.returnValue:
AttributeError: 'ClassScope' object has no attribute 'returnValue'

I started seeing weird things come out of flake8; ISTR some tracebacks getting weirdly truncated, not actually having exceptions, et cetera. Typical multiprocessing stuff.

Anyway, started bisecting, narrowed it down to this commit in my project:

426daf4c7c7c4ab512264ea3f4c0878ad50ae5bc bad
Author: Laurens Van Houtven <[email protected]>
Date:   Wed Jan 21 17:21:29 2015 -0800

    Break up a lambda

1 file changed, 4 insertions(+), 3 deletions(-)
 otter/models/cass.py | 7 ++++---

	Modified   otter/models/cass.py
diff --git a/otter/models/cass.py b/otter/models/cass.py
index 6b9c6d0..1e7f417 100644
--- a/otter/models/cass.py
+++ b/otter/models/cass.py
@@ -1471,9 +1471,10 @@ class CassScalingGroupCollection:
             _cql_health_check.format(cf=self.group_table), {},
             ConsistencyLevel.ONE)
 
-        d.addCallback(
-            lambda _: (True, {'cassandra_time': (self.reactor.seconds() - start_time)}))
-        return d
+        d.addCallback(lambda _:
+                      (True, {'cassandra_time':
+                              (self.reactor.seconds() - start_time)}))
+    return d
 
 
 @implementer(IAdmin)

So, basically it looks like flake8 doesn't deal nicely with a return being in a class body?

Output is messed when running with threads >1

In GitLab by @phdru on Jan 4, 2015, 12:05

I'm running flake8 over SQLObject sources on a 4-core notebooks with default parameters: flake8 SQLObject >result

It seems flake8 runs with more than 1 threads and messes its output. Most of lines in the result files are ok but some are broken. Examples:

SQLObject/sqlobject/views.py:58:47: E231 missing whitespace after ','
S9 characters)
SQLObject/sqlobject/sresults.py:45:80: E501 line too long (126 > 79 characters)

SQLObject/sqlobject/sqlbuilder.py:1265:1: E302 expected 2 blank lines, found 1
SQLObjefor visual indent
SQLObject/sqlobject/inheritance/iteration.py:72:21: E128 continuation line under-indented for visual indent

SQLObject/sqlobject/inheritance/tests/test_inheritance.py:3:1: F403 'from sqlobject.tests.dbtest import *' used; unable to detect undefined names
SQLObject/sqloleware.py:67:9: E301 expected 1 blank line, found 0
SQLObject/sqlobject/wsgi_middleware.py:77:9: E301 expected 1 blank line, found 0

SQLObject/sqlobject/joins.py:297:8../SQLObject/sqlobject/classregistry.py:27:1: E302 expected 2 blank lines, found 1

Running flake8 --jobs=1 SQLObject >result fixes the problem.

Python 2.7 on Debian Linux, flake8 2.2.5, pep8 1.5.7, pyflakes 0.8.1.

not reporting syntax errors if I use the "select" option.

In GitLab by @cakoose on Jan 16, 2015, 01:35

The docs for the "select" config option say "select errors and warnings to enable which are off by default". This seems to indicate that "select" can only increase the set of errors reported, but I'm seeing otherwise.

By default, syntax errors are reported:

$ cat test.py
def f(x)
    print x
$ flake8 test.py
test.py:1:10: E901 SyntaxError: invalid syntax
test.py:2:5: E113 unexpected indentation
$

But let's say I have a "setup.cfg" file in the same folder. Using the "select" option causes unexpected behavior:

$ cat setup.cfg
[flake8]
select = E101
$ flake8 test.py
$
$ cat setup.cfg
[flake8]
select = E901
$ flake8 test.py
$
$ cat setup.cfg
[flake8]
select = E113
$ flake8 test.py
test.py:2:5: E113 unexpected indentation
$

Version: 2.3.0 (pep8: 1.5.7, pyflakes: 0.8.1, mccabe: 0.3) CPython 2.7.5 on Darwin

Add warnings when users try to use --jobs and cannot

In GitLab by @sigmavirus24 on Oct 14, 2014, 13:00

If a user tries to use a feature that uses stdin (e.g., --diff or explicitly with -) with --jobs they should see a warning. Likewise, if a user is on Windows and tries to use --jobs they should see a warning.

This probably is a terrible idea to turn on by default, so we might add a "verbose" flag so users can gather information about this.

Doesn't complain about unused dunder vars

In GitLab by @ionelmc on Feb 12, 2015, 12:04

Eg:

ionel@minibox:~/osp/virtualenv$ ls -al
total 252
drwxr-xr-x 13 ionel ionel  4096 Feb 12 21:52 .
drwxrwxr-x 93 ionel ionel  4096 Feb 12 21:12 ..
drwxrwxr-x  2 ionel ionel  4096 Jan 18 02:41 .appveyor
-rw-rw-r--  1 ionel ionel  1404 Jan 18 02:41 appveyor.yml
-rw-rw-r--  1 ionel ionel  1224 Jan  5 01:43 AUTHORS.txt
drwxrwxr-x  4 ionel ionel  4096 Feb 12 20:54 build
-rw-rw-r--  1 ionel ionel   166 Jan 18 02:41 circle.yml
-rw-rw-r--  1 ionel ionel   746 Jan 18 02:41 CONTRIBUTING.rst
-rw-rw-r--  1 ionel ionel  2720 Jan 25 05:49 .coverage
-rw-rw-r--  1 ionel ionel    40 Jan 18 02:41 .coveragerc
-rw-rw-r--  1 ionel ionel   186 Jan 10 19:31 crap.py
drwxrwxr-x  2 ionel ionel  4096 Feb 12 20:54 dist
drwxrwxr-x  4 ionel ionel  4096 Jan 18 02:41 docs
drwxrwxr-x  8 ionel ionel  4096 Feb 12 22:02 .git
-rw-rw-r--  1 ionel ionel   102 Jan 18 02:41 .gitignore
drwxrwxr-x  2 ionel ionel  4096 Feb  7 23:29 .komodotools
-rw-rw-r--  1 ionel ionel  1180 Jan  5 01:43 LICENSE.txt
-rw-rw-r--  1 ionel ionel 69058 Jan 10 19:29 log
-rw-rw-r--  1 ionel ionel   285 Jan 25 07:22 MANIFEST.in
-rw-rw-r--  1 ionel ionel  1665 Jan 27 11:18 README.rst
-rw-rw-r--  1 ionel ionel    60 Jan 18 02:41 setup.cfg
-rw-rw-r--  1 ionel ionel  1978 Jan 25 07:22 setup.py
drwxrwxr-x  4 ionel ionel  4096 Jan 16 03:13 src
drwxrwxr-x  7 ionel ionel  4096 Feb  6 01:31 tests
drwxrwxr-x 10 ionel ionel  4096 Feb 12 21:52 .tox
-rw-rw-r--  1 ionel ionel  1611 Feb  6 01:38 tox.ini
-rw-rw-r--  1 ionel ionel   586 Jan 25 07:22 .travis.yml
-rw-rw-r--  1 ionel ionel 69632 Jan 13 03:36 typescript
drwxrwxr-x  7 ionel ionel  4096 Feb 12 21:01 virtualenv
drwxrwxr-x  2 ionel ionel  4096 Jan  5 01:44 virtualenv.egg-info
-rw-r-----  1 ionel ionel   659 Jan 15 11:42 virtualenv.komodoproject
ionel@minibox:~/osp/virtualenv$ ll ~/.flake*
ls: cannot access /home/ionel/.flake*: No such file or directory
ionel@minibox:~/osp/virtualenv$ .tox/py2pep8/bin/flake8 --version
2.3.0 (pep8: 1.6.1, pyflakes: 0.8.1, mccabe: 0.3, naming: 0.2.2) CPython 2.6.9 on Linux
ionel@minibox:~/osp/virtualenv$ .tox/py2pep8/bin/flake8 virtualenv/__about__.py
ionel@minibox:~/osp/virtualenv$ cat virtualenv/__about__.py
from __future__ import absolute_import, division, print_function

__title__ = "virtualenv"
__summary__ = "Virtual Python Environment Builder"
__uri__ = "https://virtualenv.pypa.io/"

__version__ = "13.0.0.dev0"

__author__ = "Python Packaging Authority"
__email__ = "[email protected]"

__license__ = "MIT"
__copyright__ = (
    "Copyright 2007-2015 {0} and individual contributors".format(__author__)
)

# noqa is not working properly (or I missed sth?)

In GitLab by @kreb on Jan 5, 2015, 04:07

Here is a simple py file with such code:

DEF_TOKENS = {                              # noqa
    # token                   is reqired?   # noqa
    'reportSchema'              : True      # noqa
}                                           # noqa

and a result of flake8 validation:

flake8 /home/prj/foo
/home/prj/foo/bar.py:4:32: E203 whitespace before ':'

Process finished with exit code 1

Hmm... seems to be an error - # noqa is not working in this case as documentation claims :(

Per-Project setting is ignored if global setting exists

In GitLab by @schlamar on Mar 26, 2015, 08:03

Steps to reproduce

  • create ~.flake8 config without a max-line-length setting
  • create a tox.ini with a flake8 section and add max-line-length = 120
  • lint a file with line length > 80

Expected

  • no error from flake8

Actual

  • tons of E501 line too long errors

Multiprocessing issue when redirecting stdout

In GitLab by @conkiztador on Dec 21, 2014, 19:59

Running 2.2.5 on linux, when I run flake8 on multiple files with a lot of violations and redirect the output at all (less, grep, >file) I often see junk in the output due to some issue with multiprocessing.

$ for i in `seq 0 1000`; do echo test$i >> testcase.py; done

$ .tox/flake8/bin/flake8 testcase.py testcase.py testcase.py | head -5
testcase.py:1:1: F821 undefined name 'test0'
testcase.py:2:1: F821 undefined name 'test1'
testcase.py:3:1: F821 undefined name 'test2'
testcase.py:4:1: F821 undefined name 'test3'

Grepping for junk:

$ .tox/flake8/bin/flake8 testcase.py testcase.py testcase.py | grep -E '^[^t]'
821 undefined name 'test422'
:256:1: F821 undefined name 'test255'
py:674:1: F821 undefined name 'test673'
 'test756'

$ .tox/flake8/bin/flake8 testcase.py testcase.py testcase.py | grep -E '^[^t]'
efined name 'test87'

$ .tox/flake8/bin/flake8 testcase.py testcase.py testcase.py | grep -E '^[^t]'
821 undefined name 'test422'
'

-j1 fixes it:

$ .tox/flake8/bin/flake8 -j1 testcase.py testcase.py testcase.py | grep -E '^[^t]'
$ .tox/flake8/bin/flake8 -j1 testcase.py testcase.py testcase.py | grep -E '^[^t]'
$ .tox/flake8/bin/flake8 -j1 testcase.py testcase.py testcase.py | grep -E '^[^t]'



$ .tox/flake8/bin/pip freeze
argparse==1.2.1
flake8==2.2.5
mccabe==0.3
pep8==1.5.7
pyflakes==0.8.1
six==1.8.0
wsgiref==0.1.2

Config silently ignored if nonexistent

In GitLab by @BanHammor on Oct 9, 2014, 03:41

The flake8 package silently ignores the configuration suggested by "--config" in case it can't access it.
That means that, in many cases, strange warnings may surface where there previously were none.

I would suggest a clear error message, like "Can't find and/or read the config file"

Hook test failing on Windows

In GitLab by @christianmlong on Mar 11, 2015, 18:06

test_hooks.TestGitHook is failing on Python 2.7, 3.3, and 3.4 on Windows 8.1

Traceback (most recent call last):
  File "c:\python34\Lib\unittest\mock.py", line 1136, in patched
    return func(*args, **keywargs)
  File "C:\Users\Me\Documents\Documents\Computer\Projects\git\flake8\flake8\tests\test_hooks.py", line 37, in test_prepends_tmp_directory_to_exclude
    style_guide.check_files.assert_called_once_with([tmpfile])
  File "c:\python34\Lib\unittest\mock.py", line 782, in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
  File "c:\python34\Lib\unittest\mock.py", line 771, in assert_called_with
    raise AssertionError(_error_message()) from cause
AssertionError: Expected call: check_files(['/fake/tmp\\:\\Users\\Me\\Documents\\Documents\\Computer\\Projects\\git\\flake8\\foo\\bfile.py'])
Actual call: check_files(['/fake/tmp\\foo\\bfile.py'])

I see two problems: the paths in the test have hardcoded posix path separators, and the path manipulation doesn't account for drive letters. I have a patch ready which I will PR soon.

Git hook doesn't work

In GitLab by @Suor on Mar 12, 2015, 18:33

$ flake8 --version
2.4.0 (pep8: 1.5.7, naming: 0.2.2, pyflakes: 0.8.1, flake8-print: 1.5.0, mccabe: 0.3) CPython 2.7.8 on Linux
$ flake8 --install-hook
$ flake8 
./tags/views.py:18:61: E226 missing whitespace around arithmetic operator
$ git commit -m 'Go on'
[master 2eda873] Go on
 1 file changed, 9 insertions(+), 6 deletions(-)

So it let the commit despite the error. This is my cat .git/hooks/pre-commit:

#!/usr/bin/env python
import sys
from flake8.hooks import git_hook, get_git_param

# `get_git_param` will retrieve configuration from your local git config and
# then fall back to using the environment variables that the hook has always
# supported.
# For example, to set the complexity, you'll need to do:
#   git config flake8.complexity 10
COMPLEXITY = get_git_param('FLAKE8_COMPLEXITY', 10)
STRICT = get_git_param('FLAKE8_STRICT', False)
IGNORE = get_git_param('FLAKE8_IGNORE')
LAZY = get_git_param('FLAKE8_LAZY', False)

if __name__ == '__main__':
    sys.exit(git_hook(
        complexity=COMPLEXITY,
        strict=STRICT,
        ignore=IGNORE,
        lazy=LAZY,
        ))

flake8 --install-hook option doesn't work

In GitLab by @nathan12343 on Sep 23, 2014, 10:32

When I try to create a flake8 commit hook in my mercurial repository, I get the following error:

$ flake8 --install-hook
Usage: flake8 [options] input ...

flake8: error: input not specified
$ flake8 --version
2.2.3 (pep8: 1.5.7, mccabe: 0.2.1, pyflakes: 0.8.1) CPython 2.7.8 on Linux

Weirdly, it seems to only happen for this one repository. I tried to debug this, but can't seem to find the place where the option parser is actually parsed.

Continuous Integration

In GitLab by @sigmavirus24 on Nov 14, 2014, 11:16

Flake8 has never had a CI system before and now that we're adding tests we should also be adding something to run tests when changes are requested to be merged and after they've been merged.

Options:

  • Prop up a Jenkins box
  • Have Travis run tests after the GitHub mirror sync's
  • ???

None of these are mutually exclusive either. I'll probably add a travis config file so that that gets run as well. It just won't run until GitHub's mirror clones the most recent changes/branches.

exclude option not being processed correctly for pep8 when run as setuptools command

In GitLab by @jcwilson on Oct 6, 2014, 15:19

I believe this issue is isolated to the setuptools invocation of flake8 (python setup.py flake8), not the more common flake8 command-line tool.

I have these settings in my project's setup.cfg:

[flake8]
max-line-length = 100
show-source = 1
verbose = 1
exclude = test/*,locales

These values are collected into Flake8Command.options_dict and passed into flake8.engine.get_style_guide(). get_style_guide() calls flake8.engine.get_parser() which creates a pep8 parser that also independently collects these values from the setup.cfg file. Then the options and parser are both passed into StyleGuide.__init__(), where the flake8 options stomp on the values provided by the pep8 parser. Unfortunately, pep8 expects the values from its parser, not those handed in from Flake8Command.options_dict.

Using the config above, it effectively prevents any flake8 style checks from running because rather than comparing candidate files against ['test/*', 'locales'], it compares them against ['t','e','s','t','/','*',',','l','o','c','a','l','e','s']. The '*' item matches everything, so everything gets excluded.

Flake8 and stdin

In GitLab by @josephbkahn on Oct 6, 2014, 15:29

In 2.2.0 I couldn't pass files through stdin and it was subsequently fixed in 2.2.1.
Since 2.2.2 it's been broken for me and I get this

Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/data/virtualenv/flake8-print/local/lib/python2.7/site-packages/flake8/reporter.py", line 54, in process_main
    self.input_file(filename)
  File "/data/virtualenv/flake8-print/local/lib/python2.7/site-packages/flake8/engine.py", line 79, in input_file
    filename, lines=lines, options=self.options)
  File "/data/virtualenv/flake8-print/local/lib/python2.7/site-packages/pep8.py", line 1230, in __init__
    self.lines = stdin_get_value().splitlines(True)
ValueError: I/O operation on closed file

Seems as though it was fixed in bitbucket Issue #155

Looking at the diff between versions I'm not sure what made it not work.

'No handlers could be found for logger "root"' error message, py2.7

In GitLab by @jwhitlock on Mar 9, 2015, 07:14

$ flake8 --version
2.3.0 (pep8: 1.6.2, pyflakes: 0.8.1, pep257: 0.2.1.post1, mccabe: 0.3) CPython 2.7.8 on Darwin
$ flake8 .
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
No handlers could be found for logger "root"
$ flake8 -j 0
No handlers could be found for logger "root"
$ flake8 -j 1
No handlers could be found for logger "root"
$ flake8 -j 2
No handlers could be found for logger "root"
No handlers could be found for logger "root"

I suspect this is a multiprocessing / logging interaction, since it varies with the number of jobs selected. It also goes away in Python 3.4.2:

$ flake8 --version
2.3.0 (pep8: 1.6.2, pyflakes: 0.8.1, pep257: 0.2.1.post1, mccabe: 0.3) CPython 3.4.2 on Darwin
$ flake8 .
$ flake8 -j 2 .

flake8 gives erroneous F821

In GitLab by @JohnVillalovos on Mar 11, 2015, 17:02

$ cat tt.py

#!/usr/bin/python -tt
import random
import sys


def main():
    f = None
    try:
        f = "bob"
        if random.choice((True, False)):
            raise Exception('test')
    except:
        del f
        raise Exception('my custom exception')
    print f


if '__main__' == __name__:
    sys.exit(main())

$ flake8 tt.py
tt.py:15:1: F821 undefined name 'f'

supressing given errors by commetns

In GitLab by @kreb on Jan 5, 2015, 06:55

The lint tool for C language has a nice feature to suppress given error in a piece of code, like that:

    /*lint -e620 */
              some code that would trigger a 620 (but now wouldn't :)
   /*lint +e620 */ 

Could you add such a feature for flake8?

"flake8 -q" doesn't list files with errors

In GitLab by @jodal on Jan 28, 2015, 06:35

flake8 --help states:

-q, --quiet report only file names, or nothing with -qq

I've tested both flake8 2.3.0 and latest from Git, and I fail to get any output at all with flake8 -q. I'm expecting it to print the filenames with errors, without any details about line numbers and error types.

Update pep8

In GitLab by @rfleschenberg on Mar 25, 2015, 07:10

The pep8 tool that comes bundled with flake8 is outdated and reports false warnings. You should update.

E.g.:

# foo.py
a = 1
b = 2
print a*b + b*b

flake8 foo.py
foo.py:4:8: E225 missing whitespace around operator
foo.py:4:14: E225 missing whitespace around operator

flake8 >= 2.2.0 fails with pep8 1.5.7 due to pkg_resources.VersionConflict with mysterious empty list

In GitLab by @dolphm on Oct 21, 2014, 06:09

I'm hoping this is a bug in setuptools or something, but I'm stumped. I've nuked my Python install on OS X (using homebrew), re-installed pip, setuptools, flake8, and pep8 from scratch (using brew-installed pip), and this is easily reproduced. It's been ongoing for over a week, perhaps since the release of https://pypi.python.org/pypi/setuptools/6.1 which has a related fix https://bitbucket.org/pypa/setuptools/issue/268 -- but reverting to setuptools 6.0.2 does not resolve the issue (also tried a much older setuptools==5.8 without success).

To reproduce (on my system, anyway):

$ pip install --upgrade setuptools flake8
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/site-packages
Downloading/unpacking flake8 from https://pypi.python.org/packages/source/f/flake8/flake8-2.2.5.tar.gz#md5=6dea927949b94c9d9495ab24bcdf9cf0
Using download cache from /Users/dolph/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Ff%2Fflake8%2Fflake8-2.2.5.tar.gz
Running setup.py (path:/private/var/folders/n5/s3phyknn2p18ls0ml6s4wm640000gn/T/pip_build_dolph/flake8/setup.py) egg_info for package flake8
    
Requirement already up-to-date: pyflakes>=0.8.1 in /usr/local/lib/python2.7/site-packages (from flake8)
Downloading/unpacking pep8>=1.5.7 (from flake8)
Using download cache from /Users/dolph/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2F3.3%2Fp%2Fpep8%2Fpep8-1.5.7-py2.py3-none-any.whl
Requirement already up-to-date: mccabe>=0.2.1 in /usr/local/lib/python2.7/site-packages (from flake8)
Installing collected packages: flake8, pep8
Found existing installation: flake8 2.1.0
    Uninstalling flake8:
    Successfully uninstalled flake8
Running setup.py install for flake8
    
    Installing flake8 script to /usr/local/bin
Found existing installation: pep8 1.5.6
    Uninstalling pep8:
    Successfully uninstalled pep8
Successfully installed flake8 pep8
Cleaning up...

And the subsequent error:

$ flake8 --version
Traceback (most recent call last):
File "/usr/local/bin/flake8", line 9, in <module>
    load_entry_point('flake8==2.2.5', 'console_scripts', 'flake8')()
File "/usr/local/lib/python2.7/site-packages/flake8/main.py", line 24, in main
    flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
File "/usr/local/lib/python2.7/site-packages/flake8/engine.py", line 102, in get_style_guide
    kwargs['parser'], options_hooks = get_parser()
File "/usr/local/lib/python2.7/site-packages/flake8/engine.py", line 55, in get_parser
    (extensions, parser_hooks, options_hooks) = _register_extensions()
File "/usr/local/lib/python2.7/site-packages/flake8/engine.py", line 28, in _register_extensions
    checker = entry.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 2182, in load
    self.require(env, installer)
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 2196, in require
    items = working_set.resolve(reqs, env, installer)
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 632, in resolve
    raise VersionConflict(tmpl % args)
pkg_resources.VersionConflict: pep8 1.5.7 is installed but pep8==1.5.6 is required by []

(pep8==1.5.6 is required by WHAT?!)

The only workaround I can find is installing flake8==2.1.0 and pep8==1.5.6 (shown below):

$ pip install --upgrade setuptools "flake8==2.1.0" "pep8==1.5.6"
Downloading/unpacking setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-7.0-py2.py3-none-any.whl#md5=918e7e5ea108507e1ffbbdfccc3496b1
Using download cache from /Users/dolph/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2F3.4%2Fs%2Fsetuptools%2Fsetuptools-7.0-py2.py3-none-any.whl
Downloading/unpacking flake8==2.1.0
Using download cache from /Users/dolph/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Ff%2Fflake8%2Fflake8-2.1.0.tar.gz
Running setup.py (path:/private/var/folders/n5/s3phyknn2p18ls0ml6s4wm640000gn/T/pip_build_dolph/flake8/setup.py) egg_info for package flake8

Downloading/unpacking pep8==1.5.6
Using download cache from /Users/dolph/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2F3.3%2Fp%2Fpep8%2Fpep8-1.5.6-py2.py3-none-any.whl
Requirement already up-to-date: pyflakes>=0.7.3 in /usr/local/lib/python2.7/site-packages (from flake8==2.1.0)
Requirement already up-to-date: mccabe>=0.2.1 in /usr/local/lib/python2.7/site-packages (from flake8==2.1.0)
Installing collected packages: setuptools, flake8, pep8
Found existing installation: setuptools 5.8
    Uninstalling setuptools:
    Successfully uninstalled setuptools
Found existing installation: flake8 2.2.5
    Uninstalling flake8:
    Successfully uninstalled flake8
Running setup.py install for flake8

    Installing flake8 script to /usr/local/bin
Found existing installation: pep8 1.5.7
    Uninstalling pep8:
    Successfully uninstalled pep8
Successfully installed setuptools flake8 pep8
Cleaning up...

This combo works:

$ flake8 --version
2.1.0 (pep8: 1.5.6, pyflakes: 0.8.1, GitCheckCommitTitleBug: 0.0.1, GitCheckCommitTitleLength: 0.0.1, GitCheckCommitTitlePeriodEnding: 0.0.1, hacking.core: 0.0.1, ProxyChecker: 0.0.1, mccabe: 0.2.1) CPython 2.7.8 on Darwin

For funsies:

$ python -c "import setuptools; print(setuptools.__version__)"
7.0

Support for specific warning ignores per-file

In GitLab by @pmdarrow on Nov 12, 2014, 08:41

It seems that flake8 only supports ignoring warnings with # flake8: noqa for the entire file or # noqa for a specific line. This is too granular - I would like to ignore a specific error type per file or line. For example, pylint supports this typo of ignore with # pylint: disable=X0123. Would love to see this same functionality in flake8.

more errors are shown when --ignore is used

In GitLab by @unode on Jan 16, 2015, 14:05

flake8 version 2.3.0 (pep8: 1.5.7, pyflakes: 0.8.1, mccabe: 0.3) CPython 2.7.7 on Linux

Sample file (test.py):

a = {
    "foo": "bar",
    }

If I run flake8 . --ignore=E501 I get:

./test.py:3:5: E123 closing bracket does not match indentation of opening bracket's line

however if I run flake8 . without ignoring anything I get no output.

Is this expected?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.