Skip to content

Commit

Permalink
Docstring length fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianv0 committed May 8, 2018
1 parent f71d30f commit 6be2f4c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
34 changes: 19 additions & 15 deletions pycodestyle.py
Expand Up @@ -345,7 +345,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
E304: @decorator\n\ndef a():\n pass
E305: def a():\n pass\na()
E306: def a():\n def b():\n pass\n def c():\n pass
""" # noqa
""" # noqa
top_level_lines = BLANK_LINES_CONFIG['top_level']
method_lines = BLANK_LINES_CONFIG['method']

Expand Down Expand Up @@ -1191,8 +1191,8 @@ def _is_binary_operator(token_type, text):
is_op_token = token_type == tokenize.OP
is_conjunction = text in ['and', 'or']
# NOTE(sigmavirus24): Previously the not_a_symbol check was executed
# conditionally. Since it is now *always* executed, text may be None.
# In that case we get a TypeError for `text not in str`.
# conditionally. Since it is now *always* executed, text may be
# None. In that case we get a TypeError for `text not in str`.
not_a_symbol = text and text not in "()[]{},:.;@=%~"
# The % character is strictly speaking a binary operator, but the
# common usage seems to be to put it next to the format parameters,
Expand Down Expand Up @@ -1548,15 +1548,16 @@ def python_3000_invalid_escape_sequence(logical_line, tokens):

@register_check
def python_3000_async_await_keywords(logical_line, tokens):
"""'async' and 'await' are reserved keywords starting with Python 3.7
"""'async' and 'await' are reserved keywords starting at Python 3.7.
W606: async = 42
W606: await = 42
Okay: async def read_data(db):\n data = await db.fetch('SELECT ...')
"""
# The Python tokenize library before Python 3.5 recognizes async/await as a
# NAME token. Therefore, use a state machine to look for the possible
# async/await constructs as defined by the Python grammar:
Okay: async def read(db):\n data = await db.fetch('SELECT ...')
""" # noqa
# The Python tokenize library before Python 3.5 recognizes
# async/await as a NAME token. Therefore, use a state machine to
# look for the possible async/await constructs as defined by the
# Python grammar:
# https://docs.python.org/3/reference/grammar.html

state = None
Expand All @@ -1571,14 +1572,15 @@ def python_3000_async_await_keywords(logical_line, tokens):
state = ('await', start)
elif state[0] == 'async_stmt':
if token_type == tokenize.NAME and text in ('def', 'with', 'for'):
# One of funcdef, with_stmt, or for_stmt. Return to looking
# for async/await names.
# One of funcdef, with_stmt, or for_stmt. Return to
# looking for async/await names.
state = None
else:
error = True
elif state[0] == 'await':
if token_type in (tokenize.NAME, tokenize.NUMBER, tokenize.STRING):
# An await expression. Return to looking for async/await names.
# An await expression. Return to looking for async/await
# names.
state = None
else:
error = True
Expand All @@ -1600,7 +1602,7 @@ def python_3000_async_await_keywords(logical_line, tokens):
)


##############################################################################
########################################################################
@register_check
def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
r"""Limit all doc lines to a maximum of 72 characters.
Expand Down Expand Up @@ -1635,6 +1637,8 @@ def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
physical_line = physical_line.decode('utf-8')
except UnicodeError:
pass
if start[0] + line_num == 1 and line.startswith('#!'):
return
length = len(physical_line)
chunks = physical_line.split()
if token_type == tokenize.COMMENT:
Expand Down Expand Up @@ -1752,8 +1756,8 @@ def parse_udiff(diff, patterns=None, parent='.'):
rv[path].update(range(row, row + nrows))
elif line[:3] == '+++':
path = line[4:].split('\t', 1)[0]
# Git diff will use (i)ndex, (w)ork tree, (c)ommit and (o)bject
# instead of a/b/c/d as prefixes for patches
# Git diff will use (i)ndex, (w)ork tree, (c)ommit and
# (o)bject instead of a/b/c/d as prefixes for patches
if path[:2] in ('b/', 'w/', 'i/'):
path = path[2:]
rv[path] = set()
Expand Down
70 changes: 36 additions & 34 deletions testsuite/test_blank_lines.py
Expand Up @@ -35,8 +35,8 @@ def assertNoErrors(self, actual):

class TestBlankLinesDefault(BlankLinesTestCase):
"""
Tests for default blank with 2 blank lines for top level and 1 blank line
for methods.
Tests for default blank with 2 blank lines for top level and 1
blank line for methods.
"""

def test_initial_no_blank(self):
Expand All @@ -51,8 +51,8 @@ def test_initial_no_blank(self):

def test_initial_lines_one_blank(self):
"""
It will accept 1 blank lines before the first line of actual code,
even if in other places it asks for 2
It will accept 1 blank lines before the first line of actual
code, even if in other places it asks for 2
"""
result = self.check("""
def some_function():
Expand All @@ -63,8 +63,8 @@ def some_function():

def test_initial_lines_two_blanks(self):
"""
It will accept 2 blank lines before the first line of actual code,
as normal.
It will accept 2 blank lines before the first line of actual
code, as normal.
"""
result = self.check("""
Expand All @@ -76,8 +76,8 @@ def some_function():

def test_method_less_blank_lines(self):
"""
It will trigger an error when less than 1 blank lin is found before
method definitions.
It will trigger an error when less than 1 blank lin is found
before method definitions.
"""
result = self.check("""# First comment line.
class X:
Expand All @@ -93,8 +93,8 @@ def b():

def test_method_less_blank_lines_comment(self):
"""
It will trigger an error when less than 1 blank lin is found before
method definition, ignoring comments.
It will trigger an error when less than 1 blank lin is found
before method definition, ignoring comments.
"""
result = self.check("""# First comment line.
class X:
Expand All @@ -111,8 +111,8 @@ def b():

def test_top_level_fewer_blank_lines(self):
"""
It will trigger an error when less 2 blank lines are found before top
level definitions.
It will trigger an error when less 2 blank lines are found
before top level definitions.
"""
result = self.check("""# First comment line.
# Second line of comment.
Expand Down Expand Up @@ -146,8 +146,8 @@ class AFarEnoughClass(object):

def test_top_level_more_blank_lines(self):
"""
It will trigger an error when more 2 blank lines are found before top
level definitions.
It will trigger an error when more 2 blank lines are found
before top level definitions.
"""
result = self.check("""# First comment line.
# Second line of comment.
Expand Down Expand Up @@ -177,8 +177,8 @@ class AFarEnoughClass(object):

def test_method_more_blank_lines(self):
"""
It will trigger an error when more than 1 blank line is found before
method definition
It will trigger an error when more than 1 blank line is found
before method definition
"""
result = self.check("""# First comment line.
Expand Down Expand Up @@ -209,8 +209,8 @@ def veryFar(self):

def test_initial_lines_more_blank(self):
"""
It will trigger an error for more than 2 blank lines before the first
line of actual code.
It will trigger an error for more than 2 blank lines before the
first line of actual code.
"""
result = self.check("""
Expand All @@ -222,8 +222,8 @@ def some_function():

def test_blank_line_between_decorator(self):
"""
It will trigger an error when the decorator is followed by a blank
line.
It will trigger an error when the decorator is followed by a
blank line.
"""
result = self.check("""# First line.
Expand All @@ -245,8 +245,8 @@ def some_method(self):

def test_blank_line_decorator(self):
"""
It will accept the decorators which are adjacent to the function and
method definition.
It will accept the decorators which are adjacent to the function
and method definition.
"""
result = self.check("""# First line.
Expand Down Expand Up @@ -340,7 +340,8 @@ def b():
def test_method_nested_fewer_follow_lines(self):
"""
It will trigger an error when less than 1 blank line is
found between a method and previous definitions, even when nested.
found between a method and previous definitions, even when
nested.
"""
result = self.check("""
def a():
Expand Down Expand Up @@ -374,7 +375,8 @@ class C:
def test_method_nested_ok(self):
"""
Will not trigger an error when 1 blank line is found
found between a method and previous definitions, even when nested.
found between a method and previous definitions, even when
nested.
"""
result = self.check("""
def a():
Expand All @@ -394,8 +396,8 @@ class C:

class TestBlankLinesTwisted(BlankLinesTestCase):
"""
Tests for blank_lines with 3 blank lines for top level and 2 blank line
for methods as used by the Twisted coding style.
Tests for blank_lines with 3 blank lines for top level and 2 blank
line for methods as used by the Twisted coding style.
"""

def setUp(self):
Expand All @@ -408,8 +410,8 @@ def tearDown(self):

def test_initial_lines_one_blanks(self):
"""
It will accept less than 3 blank lines before the first line of actual
code.
It will accept less than 3 blank lines before the first line of
actual code.
"""
result = self.check("""
Expand All @@ -422,8 +424,8 @@ def some_function():

def test_initial_lines_tree_blanks(self):
"""
It will accept 3 blank lines before the first line of actual code,
as normal.
It will accept 3 blank lines before the first line of actual
code, as normal.
"""
result = self.check("""
Expand All @@ -436,8 +438,8 @@ def some_function():

def test_top_level_fewer_blank_lines(self):
"""
It will trigger an error when less 2 blank lines are found before top
level definitions.
It will trigger an error when less 2 blank lines are found
before top level definitions.
"""
result = self.check("""# First comment line.
# Second line of comment.
Expand Down Expand Up @@ -476,8 +478,8 @@ class AFarEnoughClass(object):

def test_top_level_more_blank_lines(self):
"""
It will trigger an error when more 2 blank lines are found before top
level definitions.
It will trigger an error when more 2 blank lines are found
before top level definitions.
"""
result = self.check("""# First comment line.
# Second line of comment.
Expand Down

0 comments on commit 6be2f4c

Please sign in to comment.