summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--docs/conf.py2
-rw-r--r--docs/intro.rst2
-rwxr-xr-xpep8.py34
-rw-r--r--testsuite/E22.py12
-rw-r--r--testsuite/E40.py25
-rw-r--r--testsuite/E50.py14
-rw-r--r--testsuite/W19.py2
8 files changed, 70 insertions, 25 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index a1aacc9..774a90d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -24,6 +24,8 @@ Changes:
* Report E402 for import statements not at the top of the file. (Issue #264)
+* Do not enforce whitespaces around ``**`` operator. (Issue #292)
+
* Strip whitespace from around paths during normalization. (Issue #339 / #343)
* Update ``--format`` documentation. (Issue #198 / Pull Request #310)
@@ -43,6 +45,8 @@ Bug fixes:
* Fix false positive E711/E712/E713. (Issues #330 and #336)
+* Do not skip physical checks if the newline is escaped. (Issue #319)
+
1.5.7 (2014-05-29)
------------------
diff --git a/docs/conf.py b/docs/conf.py
index d1dca3c..a77ac83 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -128,7 +128,7 @@ html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+# html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
diff --git a/docs/intro.rst b/docs/intro.rst
index 63a1fe6..b5e3971 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -280,7 +280,7 @@ This is the current list of error and warning codes:
| E228 | missing whitespace around modulo operator |
+----------+----------------------------------------------------------------------+
+----------+----------------------------------------------------------------------+
-| E231 | missing whitespace after ',' |
+| E231 | missing whitespace after ',', ';', or ':' |
+----------+----------------------------------------------------------------------+
+----------+----------------------------------------------------------------------+
| E241 (*) | multiple spaces after ',' |
diff --git a/pep8.py b/pep8.py
index 6c51733..940a272 100755
--- a/pep8.py
+++ b/pep8.py
@@ -47,8 +47,6 @@ W warnings
"""
from __future__ import with_statement
-__version__ = '1.6.0a0'
-
import os
import sys
import re
@@ -64,6 +62,8 @@ try:
except ImportError:
from ConfigParser import RawConfigParser
+__version__ = '1.6.0a0'
+
DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'
DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704'
try:
@@ -686,7 +686,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
if need_space is True or need_space[1]:
# A needed trailing space was not found
yield prev_end, "E225 missing whitespace around operator"
- else:
+ elif prev_text != '**':
code, optype = 'E226', 'arithmetic'
if prev_text == '%':
code, optype = 'E228', 'modulo'
@@ -850,7 +850,8 @@ def module_imports_on_top_of_file(
Okay: # this is a comment\nimport os
Okay: '''this is a module docstring'''\nimport os
Okay: r'''this is a module docstring'''\nimport os
- Okay: __version__ = "123"\nimport os
+ Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y
+ Okay: try:\n import x\nexcept:\n pass\nfinally:\n pass\nimport y
E402: a=1\nimport os
E402: 'One string'\n"Two string"\nimport os
E402: a=1\nfrom sys import x
@@ -864,6 +865,8 @@ def module_imports_on_top_of_file(
line = line[1:]
return line and (line[0] == '"' or line[0] == "'")
+ allowed_try_keywords = ('try', 'except', 'else', 'finally')
+
if indent_level: # Allow imports in conditional statements or functions
return
if not logical_line: # Allow empty lines or comments
@@ -873,10 +876,10 @@ def module_imports_on_top_of_file(
line = logical_line
if line.startswith('import ') or line.startswith('from '):
if checker_state.get('seen_non_imports', False):
- yield 0, "E402 import not at top of file"
- elif line.startswith('__version__ '):
- # These lines should be included after the module's docstring, before
- # any other code, separated by a blank line above and below.
+ yield 0, "E402 module level import not at top of file"
+ elif any(line.startswith(kw) for kw in allowed_try_keywords):
+ # Allow try, except, else, finally keywords intermixed with imports in
+ # order to support conditional importing
return
elif is_string_literal(line):
# The first literal is a docstring, allow it. Otherwise, report error.
@@ -1238,14 +1241,12 @@ def filename_match(filename, patterns, default=True):
return any(fnmatch(filename, pattern) for pattern in patterns)
+def _is_eol_token(token):
+ return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n'
if COMMENT_WITH_NL:
- def _is_eol_token(token):
- return (token[0] in NEWLINE or
- (token[0] == tokenize.COMMENT and token[1] == token[4]))
-else:
- def _is_eol_token(token):
- return token[0] in NEWLINE
-
+ def _is_eol_token(token, _eol_token=_is_eol_token):
+ return _eol_token(token) or (token[0] == tokenize.COMMENT and
+ token[1] == token[4])
##############################################################################
# Framework to run all checks
@@ -1865,7 +1866,8 @@ def get_parser(prog='pep8', version=__version__):
parser.add_option('--select', metavar='errors', default='',
help="select errors and warnings (e.g. E,W6)")
parser.add_option('--ignore', metavar='errors', default='',
- help="skip errors and warnings (e.g. E4,W)")
+ help="skip errors and warnings (e.g. E4,W) "
+ "(default: %s)" % DEFAULT_IGNORE)
parser.add_option('--show-source', action='store_true',
help="show source code for each error")
parser.add_option('--show-pep8', action='store_true',
diff --git a/testsuite/E22.py b/testsuite/E22.py
index 56af307..9d8efda 100644
--- a/testsuite/E22.py
+++ b/testsuite/E22.py
@@ -89,7 +89,7 @@ c = (a+ b)*(a - b)
#:
#: E226
-z = 2**30
+z = 2//30
#: E226 E226
c = (a+b) * (a-b)
#: E226
@@ -103,8 +103,8 @@ hypot2 = x*x + y*y
#: E226
c = (a + b)*(a - b)
#: E226
-def squares(n):
- return (i**2 for i in range(n))
+def halves(n):
+ return (i//2 for i in range(n))
#: E227
_1kB = _1MB>>10
#: E227
@@ -129,7 +129,8 @@ submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
-_1MB = 2 ** 20
+_1MiB = 2 ** 20
+_1TiB = 2**30
foo(bar, key='word', *args, **kwargs)
baz(**kwargs)
negative = -1
@@ -140,7 +141,6 @@ func2(lambda a, b=h[:], c=0: (a, b, c))
if not -5 < x < +5:
print >>sys.stderr, "x is out of range."
print >> sys.stdout, "x is an integer."
-z = 2 ** 30
x = x / 2 - 1
if alpha[:-i]:
@@ -148,7 +148,7 @@ if alpha[:-i]:
def squares(n):
- return (i ** 2 for i in range(n))
+ return (i**2 for i in range(n))
ENG_PREFIXES = {
-6: "\u03bc", # Greek letter mu
diff --git a/testsuite/E40.py b/testsuite/E40.py
index d921c25..1051e32 100644
--- a/testsuite/E40.py
+++ b/testsuite/E40.py
@@ -11,3 +11,28 @@ from foo.bar.yourclass import YourClass
import myclass
import foo.bar.yourclass
+#: E402
+__all__ = ['abc']
+
+import foo
+#: Okay
+try:
+ import foo
+except:
+ pass
+else:
+ print('imported foo')
+finally:
+ print('made attempt to import foo')
+
+import bar
+#: E402
+VERSION = '1.2.3'
+
+import foo
+#: E402
+import foo
+
+a = 1
+
+import bar
diff --git a/testsuite/E50.py b/testsuite/E50.py
index 31ad6b9..f60f389 100644
--- a/testsuite/E50.py
+++ b/testsuite/E50.py
@@ -1,5 +1,19 @@
#: E501
a = '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
+#: E501
+a = '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501
+a = 7 or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501 E501
+a = 7 or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501
+a = '1234567890123456789012345678901234567890123456789012345678901234567890' # \
#: E502
a = ('123456789012345678901234567890123456789012345678901234567890123456789' \
'01234567890')
diff --git a/testsuite/W19.py b/testsuite/W19.py
index edbb1f0..afdfb76 100644
--- a/testsuite/W19.py
+++ b/testsuite/W19.py
@@ -86,7 +86,7 @@ if (a == 2 or
b == """abc def ghi
jkl mno"""):
return True
-#: E101 W191
+#: W191:2:1 W191:3:1 E101:3:2
if length > options.max_line_length:
return options.max_line_length, \
"E501 line too long (%d characters)" % length