summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst39
-rw-r--r--docs/advanced.rst21
-rw-r--r--docs/intro.rst8
-rwxr-xr-xpep8.py26
-rw-r--r--testsuite/E25.py6
-rw-r--r--testsuite/E27.py14
-rw-r--r--testsuite/test_api.py2
7 files changed, 88 insertions, 28 deletions
diff --git a/README.rst b/README.rst
index e311d4a..5619c79 100644
--- a/README.rst
+++ b/README.rst
@@ -1,11 +1,16 @@
-pep8 - Python style guide checker
-=================================
+pycodestyle (formerly called pep8) - Python style guide checker
+===============================================================
-pep8 is a tool to check your Python code against some of the style
+pycodestyle is a tool to check your Python code against some of the style
conventions in `PEP 8`_.
.. _PEP 8: http://www.python.org/dev/peps/pep-0008/
+.. note::
+
+ This package used to be called ``pep8`` but was renamed to ``pycodestyle``
+ to reduce confusion. Further discussion `here
+ <https://github.com/PyCQA/pydocstyle/issues/466>`_.
Features
--------
@@ -15,18 +20,18 @@ Features
* Parseable output: Jump to error location in your editor.
* Small: Just one Python file, requires only stdlib. You can use just
- the pep8.py file for this purpose.
+ the pycodestyle.py file for this purpose.
* Comes with a comprehensive test suite.
Installation
------------
-You can install, upgrade, uninstall pep8.py with these commands::
+You can install, upgrade, uninstall pycodestyle.py with these commands::
- $ pip install pep8
- $ pip install --upgrade pep8
- $ pip uninstall pep8
+ $ pip install pycodestyle
+ $ pip install --upgrade pycodestyle
+ $ pip uninstall pycodestyle
There's also a package for Debian/Ubuntu, but it's not always the
latest version.
@@ -36,7 +41,7 @@ Example usage and output
::
- $ pep8 --first optparse.py
+ $ pycodestyle --first optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
@@ -46,10 +51,10 @@ Example usage and output
optparse.py:472:29: E221 multiple spaces before operator
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
-You can also make pep8.py show the source code for each error, and
+You can also make pycodestyle.py show the source code for each error, and
even the relevant text from PEP 8::
- $ pep8 --show-source --show-pep8 testsuite/E40.py
+ $ pycodestyle --show-source --show-pep8 testsuite/E40.py
testsuite/E40.py:2:10: E401 multiple imports on one line
import os, sys
^
@@ -61,7 +66,7 @@ even the relevant text from PEP 8::
Or you can display how often each error was found::
- $ pep8 --statistics -qq Python-2.5/Lib
+ $ pycodestyle --statistics -qq Python-2.5/Lib
232 E201 whitespace after '['
599 E202 whitespace before ')'
631 E203 whitespace before ','
@@ -78,14 +83,14 @@ Or you can display how often each error was found::
Links
-----
-.. image:: https://api.travis-ci.org/PyCQA/pep8.png?branch=master
- :target: https://travis-ci.org/PyCQA/pep8
+.. image:: https://api.travis-ci.org/PyCQA/pycodestyle.png?branch=master
+ :target: https://travis-ci.org/PyCQA/pycodestyle
:alt: Build status
-.. image:: https://pypip.in/wheel/pep8/badge.png?branch=master
- :target: https://pypi.python.org/pypi/pep8
+.. image:: https://pypip.in/wheel/pycodestyle/badge.png?branch=master
+ :target: https://pypi.python.org/pypi/pycodestyle
:alt: Wheel Status
-* `Read the documentation <http://pep8.readthedocs.org/>`_
+* `Read the documentation <http://pycodestyle.readthedocs.org/>`_
* `Fork me on GitHub <http://github.com/PyCQA/pycodestyle>`_
diff --git a/docs/advanced.rst b/docs/advanced.rst
index 62c1b90..de3be69 100644
--- a/docs/advanced.rst
+++ b/docs/advanced.rst
@@ -8,7 +8,7 @@ Advanced usage
Automated tests
---------------
-You can also execute `pep8` tests from Python code. For example, this
+You can also execute ``pep8`` tests from Python code. For example, this
can be highly useful for automated testing of coding style conformance
in your project::
@@ -25,7 +25,7 @@ in your project::
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")
-If you are using `nosetests` for running tests, remove `quiet=True`
+If you are using ``nosetests`` for running tests, remove ``quiet=True``
since Nose suppresses stdout.
There's also a shortcut for checking a single file::
@@ -38,6 +38,23 @@ There's also a shortcut for checking a single file::
print("Found %s errors (and warnings)" % file_errors)
+Configuring tests
+-----------------
+
+You can configure automated ``pep8`` tests in a variety of ways.
+
+For example, you can pass in a path to a configuration file that ``pep8``
+should use::
+
+ import pep8
+
+ pep8style = pep8.StyleGuide(config_file='/path/to/tox.ini')
+
+You can also set specific options explicitly::
+
+ pep8style = pep8.StyleGuide(ignore=['E501'])
+
+
Skip file header
----------------
diff --git a/docs/intro.rst b/docs/intro.rst
index 6d1b191..5f7e9cd 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -313,6 +313,8 @@ This is the current list of error and warning codes:
+------------+----------------------------------------------------------------------+
| E274 | tab before keyword |
+------------+----------------------------------------------------------------------+
+| E275 | missing whitespace after keyword |
++------------+----------------------------------------------------------------------+
+------------+----------------------------------------------------------------------+
| **E3** | *Blank line* |
+------------+----------------------------------------------------------------------+
@@ -390,7 +392,7 @@ This is the current list of error and warning codes:
+------------+----------------------------------------------------------------------+
| **W5** | *Line break warning* |
+------------+----------------------------------------------------------------------+
-| W503 | line break occurred before a binary operator |
+| W503 (*) | line break occurred before a binary operator |
+------------+----------------------------------------------------------------------+
+------------+----------------------------------------------------------------------+
| **W6** | *Deprecation warning* |
@@ -406,8 +408,8 @@ This is the current list of error and warning codes:
**(*)** In the default configuration, the checks **E121**, **E123**, **E126**,
-**E133**, **E226**, **E241**, **E242** and **E704** are ignored because they
-are not rules unanimously accepted, and `PEP 8`_ does not enforce them. The
+**E133**, **E226**, **E241**, **E242**, **E704** and **W503** are ignored because
+they are not rules unanimously accepted, and `PEP 8`_ does not enforce them. The
check **E133** is mutually exclusive with check **E123**. Use switch ``--hang-
closing`` to report **E133** instead of **E123**.
diff --git a/pep8.py b/pep8.py
index ef6c7cf..0d329f3 100755
--- a/pep8.py
+++ b/pep8.py
@@ -65,7 +65,7 @@ except ImportError:
__version__ = '1.8.0-dev'
DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'
-DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704'
+DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503'
try:
if sys.platform == 'win32':
USER_CONFIG = os.path.expanduser(r'~\.pep8')
@@ -325,6 +325,23 @@ def whitespace_around_keywords(logical_line):
yield match.start(2), "E271 multiple spaces after keyword"
+def missing_whitespace_after_import_keyword(logical_line):
+ r"""Multiple imports in form from x import (a, b, c) should have space
+ between import statement and parenthesised name list.
+
+ Okay: from foo import (bar, baz)
+ E275: from foo import(bar, baz)
+ E275: from importable.module import(bar, baz)
+ """
+ line = logical_line
+ indicator = ' import('
+ if line.startswith('from '):
+ found = line.find(indicator)
+ if -1 < found:
+ pos = found + len(indicator) - 1
+ yield pos, "E275 missing whitespace after keyword"
+
+
def missing_whitespace(logical_line):
r"""Each comma, semicolon or colon should be followed by whitespace.
@@ -759,6 +776,7 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
Okay: boolean(a <= b)
Okay: boolean(a >= b)
Okay: def foo(arg: int = 42):
+ Okay: async def foo(arg: int = 42):
E251: def complex(real, imag = 0.0):
E251: return magic(r = real, i = imag)
@@ -767,7 +785,7 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
no_space = False
prev_end = None
annotated_func_arg = False
- in_def = logical_line.startswith('def')
+ in_def = logical_line.startswith(('def', 'async def'))
message = "E251 unexpected spaces around keyword / parameter equals"
for token_type, text, start, end, line in tokens:
if token_type == tokenize.NL:
@@ -777,9 +795,9 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
if start != prev_end:
yield (prev_end, message)
if token_type == tokenize.OP:
- if text == '(':
+ if text in '([':
parens += 1
- elif text == ')':
+ elif text in ')]':
parens -= 1
elif in_def and text == ':' and parens == 1:
annotated_func_arg = True
diff --git a/testsuite/E25.py b/testsuite/E25.py
index ad8db88..7a536b5 100644
--- a/testsuite/E25.py
+++ b/testsuite/E25.py
@@ -32,5 +32,9 @@ d[type(None)] = _deepcopy_atomic
# Annotated Function Definitions
#: Okay
-def munge(input: AnyStr, sep: AnyStr = None, limit=1000) -> AnyStr:
+def munge(input: AnyStr, sep: AnyStr = None, limit=1000,
+ extra: Union[str, dict] = None) -> AnyStr:
pass
+#: Okay
+async def add(a: int = 0, b: int = 0) -> int:
+ return a + b
diff --git a/testsuite/E27.py b/testsuite/E27.py
index f9d3e8e..888b3a8 100644
--- a/testsuite/E27.py
+++ b/testsuite/E27.py
@@ -28,3 +28,17 @@ a and b
a and b
#: E273 E274
this and False
+#: Okay
+from u import (a, b)
+from v import c, d
+#: E271
+from w import (e, f)
+#: E275
+from w import(e, f)
+#: E275
+from importable.module import(e, f)
+#: E275
+try:
+ from importable.module import(e, f)
+except ImportError:
+ pass
diff --git a/testsuite/test_api.py b/testsuite/test_api.py
index 1cb0d4b..0b83c4e 100644
--- a/testsuite/test_api.py
+++ b/testsuite/test_api.py
@@ -181,7 +181,7 @@ class APITestCase(unittest.TestCase):
self.assertEqual(options.select, ())
self.assertEqual(
options.ignore,
- ('E121', 'E123', 'E126', 'E226', 'E24', 'E704')
+ ('E121', 'E123', 'E126', 'E226', 'E24', 'E704', 'W503')
)
options = parse_argv('--doctest').options