4
Summary: Python style guide checker
5
Home-page: https://pycodestyle.readthedocs.io/
7
Author-email: IanLee1521@gmail.com
9
Keywords: pycodestyle,pep8,PEP 8,PEP-8,PEP8
11
Classifier: Development Status :: 5 - Production/Stable
12
Classifier: Environment :: Console
13
Classifier: Intended Audience :: Developers
14
Classifier: License :: OSI Approved :: MIT License
15
Classifier: Operating System :: OS Independent
16
Classifier: Programming Language :: Python
17
Classifier: Programming Language :: Python :: 2
18
Classifier: Programming Language :: Python :: 3
19
Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
pycodestyle (formerly called pep8) - Python style guide checker
22
===============================================================
24
.. image:: https://img.shields.io/travis/PyCQA/pycodestyle.svg
25
:target: https://travis-ci.org/PyCQA/pycodestyle
28
.. image:: https://readthedocs.org/projects/pycodestyle/badge/?version=latest
29
:target: https://pycodestyle.readthedocs.io
30
:alt: Documentation Status
32
.. image:: https://img.shields.io/pypi/wheel/pycodestyle.svg
33
:target: https://pypi.python.org/pypi/pycodestyle
36
.. image:: https://badges.gitter.im/PyCQA/pycodestyle.svg
37
:alt: Join the chat at https://gitter.im/PyCQA/pycodestyle
38
:target: https://gitter.im/PyCQA/pycodestyle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
40
pycodestyle is a tool to check your Python code against some of the style
41
conventions in `PEP 8`_.
43
.. _PEP 8: http://www.python.org/dev/peps/pep-0008/
47
This package used to be called ``pep8`` but was renamed to ``pycodestyle``
48
to reduce confusion. Further discussion can be found `in the issue where
50
change <https://github.com/PyCQA/pycodestyle/issues/466>`_, or in the
51
lightning talk at PyCon 2016 by @IanLee1521:
52
`slides <https://speakerdeck.com/ianlee1521/pep8-vs-pep-8>`_
53
`video <https://youtu.be/PulzIT8KYLk?t=36m>`_.
58
* Plugin architecture: Adding new checks is easy.
60
* Parseable output: Jump to error location in your editor.
62
* Small: Just one Python file, requires only stdlib. You can use just
63
the ``pycodestyle.py`` file for this purpose.
65
* Comes with a comprehensive test suite.
70
You can install, upgrade, and uninstall ``pycodestyle.py`` with these commands::
72
$ pip install pycodestyle
73
$ pip install --upgrade pycodestyle
74
$ pip uninstall pycodestyle
76
There's also a package for Debian/Ubuntu, but it's not always the
79
Example usage and output
80
------------------------
84
$ pycodestyle --first optparse.py
85
optparse.py:69:11: E401 multiple imports on one line
86
optparse.py:77:1: E302 expected 2 blank lines, found 1
87
optparse.py:88:5: E301 expected 1 blank line, found 0
88
optparse.py:222:34: W602 deprecated form of raising exception
89
optparse.py:347:31: E211 whitespace before '('
90
optparse.py:357:17: E201 whitespace after '{'
91
optparse.py:472:29: E221 multiple spaces before operator
92
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
94
You can also make ``pycodestyle.py`` show the source code for each error, and
95
even the relevant text from PEP 8::
97
$ pycodestyle --show-source --show-pep8 testsuite/E40.py
98
testsuite/E40.py:2:10: E401 multiple imports on one line
101
Imports should usually be on separate lines.
103
Okay: import os\nimport sys
107
Or you can display how often each error was found::
109
$ pycodestyle --statistics -qq Python-2.5/Lib
110
232 E201 whitespace after '['
111
599 E202 whitespace before ')'
112
631 E203 whitespace before ','
113
842 E211 whitespace before '('
114
2531 E221 multiple spaces before operator
115
4473 E301 expected 1 blank line, found 0
116
4006 E302 expected 2 blank lines, found 1
117
165 E303 too many blank lines (4)
118
325 E401 multiple imports on one line
119
3615 E501 line too long (82 characters)
120
612 W601 .has_key() is deprecated, use 'in'
121
1188 W602 deprecated form of raising exception
126
* `Read the documentation <https://pycodestyle.readthedocs.io/>`_
128
* `Fork me on GitHub <http://github.com/PyCQA/pycodestyle>`_
139
* Fix regression in detection of E302 and E306; #618, #620
146
* Add E722 warning for bare ``except`` clauses
147
* Report E704 for async function definitions (``async def``)
151
* Fix another E305 false positive for variables beginning with "class" or
153
* Fix detection of multiple spaces betwen ``async`` and ``def``
154
* Fix handling of variable annotations. Stop reporting E701 on Python 3.6 for
155
variable annotations.
162
* Added Make target to obtain proper tarball file permissions; #599
166
* Fixed E305 regression caused by #400; #593
173
* Change all references to the pep8 project to say pycodestyle; #530
177
* Report E302 for blank lines before an "async def"; #556
178
* Update our list of tested and supported Python versions which are 2.6, 2.7,
179
3.2, 3.3, 3.4 and 3.5 as well as the nightly Python build and PyPy.
180
* Report E742 and E743 for functions and classes badly named 'l', 'O', or 'I'.
181
* Report E741 on 'global' and 'nonlocal' statements, as well as prohibited
182
single-letter variables.
183
* Deprecated use of `[pep8]` section name in favor of `[pycodestyle]`; #591
184
* Report E722 when bare except clause is used; #579
188
* Fix opt_type AssertionError when using Flake8 2.6.2 and pycodestyle; #561
189
* Require two blank lines after toplevel def, class; #536
190
* Remove accidentally quadratic computation based on the number of colons. This
191
will make pycodestyle faster in some cases; #314
198
* Repository renamed to `pycodestyle`; Issue #466 / #481.
199
* Added joint Code of Conduct as member of PyCQA; #483
203
* Added tox test support for Python 3.5 and pypy3
204
* Added check E275 for whitespace on `from ... import ...` lines; #489 / #491
205
* Added W503 to the list of codes ignored by default ignore list; #498
206
* Removed use of project level `.pep8` configuration file; #364
210
* Fixed bug with treating `~` operator as binary; #383 / #384
211
* Identify binary operators as unary; #484 / #485
218
* Repository moved to PyCQA Organization on GitHub:
219
https://github.com/pycqa/pep8
223
* Reverted the fix in #368, "options passed on command line are only ones
224
accepted" feature. This has many unintended consequences in pep8 and flake8
225
and needs to be reworked when I have more time.
226
* Added support for Python 3.5. (Issue #420 & #459)
227
* Added support for multi-line config_file option parsing. (Issue #429)
228
* Improved parameter parsing. (Issues #420 & #456)
232
* Fixed BytesWarning on Python 3. (Issue #459)
239
* Added check for breaking around a binary operator. (Issue #197, Pull #305)
243
* Restored config_file parameter in process_options(). (Issue #380)
251
* Assign variables before referenced. (Issue #287)
255
* Exception thrown due to unassigned ``local_dir`` variable. (Issue #377)
263
* Ian Lee <ianlee1521@gmail.com> joined the project as a maintainer.
267
* Report E731 for lambda assignment. (Issue #277)
269
* Report E704 for one-liner def instead of E701.
270
Do not report this error in the default configuration. (Issue #277)
272
* Replace codes E111, E112 and E113 with codes E114, E115 and E116
273
for bad indentation of comments. (Issue #274)
275
* Report E266 instead of E265 when the block comment starts with
276
multiple ``#``. (Issue #270)
278
* Report E402 for import statements not at the top of the file. (Issue #264)
280
* Do not enforce whitespaces around ``**`` operator. (Issue #292)
282
* Strip whitespace from around paths during normalization. (Issue #339 / #343)
284
* Update ``--format`` documentation. (Issue #198 / Pull Request #310)
286
* Add ``.tox/`` to default excludes. (Issue #335)
288
* Do not report E121 or E126 in the default configuration. (Issues #256 / #316)
290
* Allow spaces around the equals sign in an annotated function. (Issue #357)
292
* Allow trailing backslash if in an inline comment. (Issue #374)
294
* If ``--config`` is used, only that configuration is processed. Otherwise,
295
merge the user and local configurations are merged. (Issue #368 / #369)
299
* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
301
* Don't crash if os.path.expanduser() throws an ImportError. (Issue #297)
303
* Missing space around keyword parameter equal not always reported, E251.
306
* Fix false positive E711/E712/E713. (Issues #330 and #336)
308
* Do not skip physical checks if the newline is escaped. (Issue #319)
310
* Flush sys.stdout to avoid race conditions with printing. See flake8 bug:
311
https://gitlab.com/pycqa/flake8/issues/17 for more details. (Issue #363)
319
* Skip the traceback on "Broken pipe" signal. (Issue #275)
321
* Do not exit when an option in ``setup.cfg`` or ``tox.ini``
324
* Check the last line even if it does not end with a newline. (Issue #286)
326
* Always open files in universal newlines mode in Python 2. (Issue #288)
334
* Check the last line even if it has no end-of-line. (Issue #273)
342
* Fix regression with E22 checks and inline comments. (Issue #271)
350
* Fix negative offset with E303 before a multi-line docstring.
359
* Fix wrong offset computation when error is on the last char
360
of a physical line. (Issue #268)
368
* Distribute a universal wheel file.
372
* Report correct line number for E303 with comments. (Issue #60)
374
* Do not allow newline after parameter equal. (Issue #252)
376
* Fix line number reported for multi-line strings. (Issue #220)
378
* Fix false positive E121/E126 with multi-line strings. (Issue #265)
380
* Fix E501 not detected in comments with Python 2.5.
382
* Fix caret position with ``--show-source`` when line contains tabs.
390
* Fix a crash with E125 on multi-line strings. (Issue #263)
398
* Report E129 instead of E125 for visually indented line with same
399
indent as next logical line. (Issue #126)
401
* Report E265 for space before block comment. (Issue #190)
403
* Report E713 and E714 when operators ``not in`` and ``is not`` are
404
recommended. (Issue #236)
406
* Allow long lines in multiline strings and comments if they cannot
407
be wrapped. (Issue #224).
409
* Optionally disable physical line checks inside multiline strings,
410
using ``# noqa``. (Issue #242)
412
* Change text for E121 to report "continuation line under-indented
413
for hanging indent" instead of indentation not being a
416
* Report E131 instead of E121 / E126 if the hanging indent is not
417
consistent within the same continuation block. It helps when
418
error E121 or E126 is in the ``ignore`` list.
420
* Report E126 instead of E121 when the continuation line is hanging
421
with extra indentation, even if indentation is not a multiple of 4.
425
* Allow the checkers to report errors on empty files. (Issue #240)
427
* Fix ignoring too many checks when ``--select`` is used with codes
428
declared in a flake8 extension. (Issue #216)
430
* Fix regression with multiple brackets. (Issue #214)
432
* Fix ``StyleGuide`` to parse the local configuration if the
433
keyword argument ``paths`` is specified. (Issue #246)
435
* Fix a false positive E124 for hanging indent. (Issue #254)
437
* Fix a false positive E126 with embedded colon. (Issue #144)
439
* Fix a false positive E126 when indenting with tabs. (Issue #204)
441
* Fix behaviour when ``exclude`` is in the configuration file and
442
the current directory is not the project directory. (Issue #247)
444
* The logical checks can return ``None`` instead of an empty iterator.
447
* Do not report multiple E101 if only the first indentation starts
448
with a tab. (Issue #237)
450
* Fix a rare false positive W602. (Issue #34)
458
* Honor ``# noqa`` for errors E711 and E712. (Issue #180)
460
* When both a ``tox.ini`` and a ``setup.cfg`` are present in the project
461
directory, merge their contents. The ``tox.ini`` file takes
462
precedence (same as before). (Issue #182)
464
* Give priority to ``--select`` over ``--ignore``. (Issue #188)
466
* Compare full path when excluding a file. (Issue #186)
468
* New option ``--hang-closing`` to switch to the alternative style of
469
closing bracket indentation for hanging indent. Add error E133 for
470
closing bracket which is missing indentation. (Issue #103)
472
* Accept both styles of closing bracket indentation for hanging indent.
473
Do not report error E123 in the default configuration. (Issue #103)
477
* Do not crash when running AST checks and the document contains null bytes.
480
* Correctly report other E12 errors when E123 is ignored. (Issue #103)
482
* Fix false positive E261/E262 when the file contains a BOM. (Issue #193)
484
* Fix E701, E702 and E703 not detected sometimes. (Issue #196)
486
* Fix E122 not detected in some cases. (Issue #201 and #208)
488
* Fix false positive E121 with multiple brackets. (Issue #203)
494
* When no path is specified, do not try to read from stdin. The feature
495
was added in 1.4.3, but it is not supported on Windows. Use ``-``
496
filename argument to read from stdin. This usage is supported
497
since 1.3.4. (Issue #170)
499
* Do not require ``setuptools`` in setup.py. It works around an issue
500
with ``pip`` and Python 3. (Issue #172)
502
* Add ``__pycache__`` to the ignore list.
504
* Change misleading message for E251. (Issue #171)
506
* Do not report false E302 when the source file has a coding cookie or a
507
comment on the first line. (Issue #174)
509
* Reorganize the tests and add tests for the API and for the command line
510
usage and options. (Issues #161 and #162)
512
* Ignore all checks which are not explicitly selected when ``select`` is
513
passed to the ``StyleGuide`` constructor.
519
* Report E227 or E228 instead of E225 for whitespace around bitwise, shift
520
or modulo operators. (Issue #166)
522
* Change the message for E226 to make clear that it is about arithmetic
525
* Fix a false positive E128 for continuation line indentation with tabs.
527
* Fix regression with the ``--diff`` option. (Issue #169)
529
* Fix the ``TestReport`` class to print the unexpected warnings and
536
* Hide the ``--doctest`` and ``--testsuite`` options when installed.
538
* Fix crash with AST checkers when the syntax is invalid. (Issue #160)
540
* Read from standard input if no path is specified.
542
* Initiate a graceful shutdown on ``Control+C``.
544
* Allow changing the ``checker_class`` for the ``StyleGuide``.
550
* Support AST checkers provided by third-party applications.
552
* Register new checkers with ``register_check(func_or_cls, codes)``.
554
* Allow constructing a ``StyleGuide`` with a custom parser.
556
* Accept visual indentation without parenthesis after the ``if``
557
statement. (Issue #151)
559
* Fix UnboundLocalError when using ``# noqa`` with continued lines.
562
* Re-order the lines for the ``StandardReport``.
564
* Expand tabs when checking E12 continuation lines. (Issue #155)
566
* Refactor the testing class ``TestReport`` and the specific test
567
functions into a separate test module.
573
* Allow sphinx.ext.autodoc syntax for comments. (Issue #110)
575
* Report E703 instead of E702 for the trailing semicolon. (Issue #117)
577
* Honor ``# noqa`` in addition to ``# nopep8``. (Issue #149)
579
* Expose the ``OptionParser`` factory for better extensibility.
585
* Report E226 instead of E225 for optional whitespace around common
586
operators (``*``, ``**``, ``/``, ``+`` and ``-``). This new error
587
code is ignored in the default configuration because PEP 8 recommends
588
to "use your own judgement". (Issue #96)
590
* Lines with a ``# nopep8`` at the end will not issue errors on line
591
length E501 or continuation line indentation E12*. (Issue #27)
593
* Fix AssertionError when the source file contains an invalid line
594
ending ``"\r\r\n"``. (Issue #119)
596
* Read the ``[pep8]`` section of ``tox.ini`` or ``setup.cfg`` if present.
599
* Add the Sphinx-based documentation, and publish it
600
on https://pycodestyle.readthedocs.io/. (Issue #105)
606
* Fix false positive E124 and E128 with comments. (Issue #100)
608
* Fix error on stdin when running with bpython. (Issue #101)
610
* Fix false positive E401. (Issue #104)
612
* Report E231 for nested dictionary in list. (Issue #142)
614
* Catch E271 at the beginning of the line. (Issue #133)
616
* Fix false positive E126 for multi-line comments. (Issue #138)
618
* Fix false positive E221 when operator is preceded by a comma. (Issue #135)
620
* Fix ``--diff`` failing on one-line hunk. (Issue #137)
622
* Fix the ``--exclude`` switch for directory paths. (Issue #111)
624
* Use ``-`` filename to read from standard input. (Issue #128)
630
* Fix regression with continuation line checker. (Issue #98)
636
* Revert to the previous behaviour for ``--show-pep8``:
637
do not imply ``--first``. (Issue #89)
639
* Add E902 for IO errors. (Issue #87)
641
* Fix false positive for E121, and missed E124. (Issue #92)
643
* Set a sensible default path for config file on Windows. (Issue #95)
645
* Allow ``verbose`` in the configuration file. (Issue #91)
647
* Show the enforced ``max-line-length`` in the error message. (Issue #86)
653
* Explain which configuration options are expected. Accept and recommend
654
the options names with hyphen instead of underscore. (Issue #82)
656
* Do not read the user configuration when used as a module
657
(except if ``config_file=True`` is passed to the ``StyleGuide`` constructor).
659
* Fix wrong or missing cases for the E12 series.
661
* Fix cases where E122 was missed. (Issue #81)
668
The internal API is backwards incompatible.
670
* Remove global configuration and refactor the library around
671
a ``StyleGuide`` class; add the ability to configure various
672
reporters. (Issue #35 and #66)
674
* Read user configuration from ``~/.config/pep8``
675
and local configuration from ``./.pep8``. (Issue #22)
677
* Fix E502 for backslash embedded in multi-line string. (Issue #68)
679
* Fix E225 for Python 3 iterable unpacking (PEP 3132). (Issue #72)
681
* Enable the new checkers from the E12 series in the default
684
* Suggest less error-prone alternatives for E712 errors.
686
* Rewrite checkers to run faster (E22, E251, E27).
688
* Fixed a crash when parsed code is invalid (too many
691
* Fix E127 and E128 for continuation line indentation. (Issue #74)
693
* New option ``--format`` to customize the error format. (Issue #23)
695
* New option ``--diff`` to check only modified code. The unified
696
diff is read from STDIN. Example: ``hg diff | pep8 --diff``
699
* Correctly report the count of failures and set the exit code to 1
700
when the ``--doctest`` or the ``--testsuite`` fails.
702
* Correctly detect the encoding in Python 3. (Issue #69)
704
* Drop support for Python 2.3, 2.4 and 3.0. (Issue #78)
710
* Add E121 through E128 for continuation line indentation. These
711
checks are disabled by default. If you want to force all checks,
712
use switch ``--select=E,W``. Patch by Sam Vilain. (Issue #64)
714
* Add E721 for direct type comparisons. (Issue #47)
716
* Add E711 and E712 for comparisons to singletons. (Issue #46)
718
* Fix spurious E225 and E701 for function annotations. (Issue #29)
720
* Add E502 for explicit line join between brackets.
722
* Fix E901 when printing source with ``--show-source``.
724
* Report all errors for each checker, instead of reporting only the
725
first occurrence for each line.
727
* Option ``--show-pep8`` implies ``--first``.
733
* Add E901 for syntax errors. (Issues #63 and #30)
735
* Add E271, E272, E273 and E274 for extraneous whitespace around
736
keywords. (Issue #57)
738
* Add ``tox.ini`` configuration file for tests. (Issue #61)
740
* Add ``.travis.yml`` configuration file for continuous integration.
747
* Fix inconsistent version numbers.
753
* Fix W602 ``raise`` to handle multi-char names. (Issue #53)
759
* Now ``--first`` prints only the first occurrence of each error.
760
The ``--repeat`` flag becomes obsolete because it is the default
761
behaviour. (Issue #6)
763
* Allow specifying ``--max-line-length``. (Issue #36)
765
* Make the shebang more flexible. (Issue #26)
767
* Add testsuite to the bundle. (Issue #25)
769
* Fixes for Jython. (Issue #49)
771
* Add PyPI classifiers. (Issue #43)
773
* Fix the ``--exclude`` option. (Issue #48)
775
* Fix W602, accept ``raise`` with 3 arguments. (Issue #34)
777
* Correctly select all tests if ``DEFAULT_IGNORE == ''``.
783
* Fix inconsistent version numbers. (Issue #21)
789
* Test suite reorganized and enhanced in order to check more failures
790
with fewer test files. Read the ``run_tests`` docstring for details
793
* Fix E225: accept ``print >>sys.stderr, "..."`` syntax.
795
* Fix E501 for lines containing multibyte encoded characters. (Issue #7)
797
* Fix E221, E222, E223, E224 not detected in some cases. (Issue #16)
799
* Fix E211 to reject ``v = dic['a'] ['b']``. (Issue #17)
801
* Exit code is always 1 if any error or warning is found. (Issue #10)
803
* ``--ignore`` checks are now really ignored, especially in
804
conjunction with ``--count``. (Issue #8)
806
* Blank lines with spaces yield W293 instead of W291: some developers
807
want to ignore this warning and indent the blank lines to paste their
808
code easily in the Python interpreter.
810
* Fix E301: do not require a blank line before an indented block. (Issue #14)
812
* Fix E203 to accept NumPy slice notation ``a[0, :]``. (Issue #13)
814
* Performance improvements.
816
* Fix decoding and checking non-UTF8 files in Python 3.
818
* Fix E225: reject ``True+False`` when running on Python 3.
820
* Fix an exception when the line starts with an operator.
822
* Allow a new line before closing ``)``, ``}`` or ``]``. (Issue #5)
828
* Changed the ``--count`` switch to print to sys.stderr and set
829
exit code to 1 if any error or warning is found.
831
* E241 and E242 are removed from the standard checks. If you want to
832
include these checks, use switch ``--select=E,W``. (Issue #4)
834
* Blank line is not mandatory before the first class method or nested
835
function definition, even if there's a docstring. (Issue #1)
837
* Add the switch ``--version``.
839
* Fix decoding errors with Python 3. (Issue #13 [1]_)
841
* Add ``--select`` option which is mirror of ``--ignore``.
843
* Add checks E261 and E262 for spaces before inline comments.
845
* New check W604 warns about deprecated usage of backticks.
847
* New check W603 warns about the deprecated operator ``<>``.
849
* Performance improvement, due to rewriting of E225.
853
- no whitespace after unary operator or similar. (Issue #9 [1]_)
855
- lambda function with argument unpacking or keyword defaults.
857
* Reserve "2 blank lines" for module-level logical blocks. (E303)
859
* Allow multi-line comments. (E302, issue #10 [1]_)
865
* Decorators on classes and class methods are OK now.
871
* Support for all versions of Python from 2.3 to 3.1.
873
* New and greatly expanded self tests.
875
* Added ``--count`` option to print the total number of errors and warnings.
877
* Further improvements to the handling of comments and blank lines.
878
(Issue #1 [1]_ and others changes.)
880
* Check all py files in directory when passed a directory (Issue
881
#2 [1]_). This also prevents an exception when traversing directories
882
with non ``*.py`` files.
884
* E231 should allow commas to be followed by ``)``. (Issue #3 [1]_)
886
* Spaces are no longer required around the equals sign for keyword
887
arguments or default parameter values.
890
.. [1] These issues refer to the `previous issue tracker`__.
891
.. __: http://github.com/cburroughs/pep8.py/issues
897
* Fixes for comments: do not count them when checking for blank lines between
900
* Added setup.py for pypi upload and easy_installability.
906
* Loads of fixes and improvements.