summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt10
-rw-r--r--docs/advanced.rst21
-rw-r--r--docs/intro.rst8
-rwxr-xr-xpep8.py37
-rw-r--r--testsuite/E25.py6
-rw-r--r--testsuite/E27.py14
-rw-r--r--testsuite/test_api.py2
7 files changed, 86 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6e853eb..d25315a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,16 @@ Changelog
Announcements:
* Repository renamed to `pycodestyle`; Issue #466 / $481.
+* Added joint Code of Conduct as member of PyCQA; #483
+
+Changes:
+
+* Added tox test support for Python 3.5 and pypy3
+
+Bugs:
+
+* Fixed bug with treating `~` operator as binary; #384
+* Identify binary operators as unary; #484
1.7.0 (2016-01-12)
------------------
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 bfbea7f..247a626 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
@@ -1018,6 +1036,8 @@ def break_around_binary_operator(logical_line, tokens):
Okay: foo(x,\n -y)
Okay: foo(x, # comment\n -y)
Okay: var = (1 &\n ~2)
+ Okay: var = (1 /\n -2)
+ Okay: var = (1 +\n -1 +\n -2)
"""
def is_binary_operator(token_type, text):
# The % character is strictly speaking a binary operator, but the
@@ -1028,6 +1048,9 @@ def break_around_binary_operator(logical_line, tokens):
line_break = False
unary_context = True
+ # Previous non-newline token types and text
+ previous_token_type = None
+ previous_text = None
for token_type, text, start, end, line in tokens:
if token_type == tokenize.COMMENT:
continue
@@ -1035,10 +1058,14 @@ def break_around_binary_operator(logical_line, tokens):
line_break = True
else:
if (is_binary_operator(token_type, text) and line_break and
- not unary_context):
+ not unary_context and
+ not is_binary_operator(previous_token_type,
+ previous_text)):
yield start, "W503 line break before binary operator"
unary_context = text in '([{,;'
line_break = False
+ previous_token_type = token_type
+ previous_text = text
def comparison_to_singleton(logical_line, noqa):
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