Skip to content

Commit

Permalink
Remove some lint warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwendling committed Apr 21, 2015
1 parent 4372f26 commit ffcbff1
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 23 deletions.
13 changes: 7 additions & 6 deletions yapf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def main(argv):
Returns:
0 if there were no errors, non-zero otherwise.
Raises:
YapfError: if none of the supplied files were Python files.
"""
parser = argparse.ArgumentParser(description='Formatter for Python code.')
parser.add_argument('--version',
Expand Down Expand Up @@ -99,7 +102,7 @@ def main(argv):
if args.style_help:
style.SetGlobalStyle(style.CreateStyleFromConfig(args.style))
for option, docstring in sorted(style.Help().items()):
print(option, "=", style.Get(option), sep='')
print(option, '=', style.Get(option), sep='')
for line in docstring.splitlines():
print(' ', line)
print()
Expand Down Expand Up @@ -166,11 +169,9 @@ def FormatFiles(filenames, lines,
for filename in filenames:
logging.info('Reformatting %s', filename)
try:
reformatted_code, encoding = yapf_api.FormatFile(filename,
style_config=style_config,
lines=lines,
print_diff=print_diff,
verify=verify)
reformatted_code, encoding = yapf_api.FormatFile(
filename, style_config=style_config, lines=lines,
print_diff=print_diff, verify=verify)
except SyntaxError as e:
e.filename = filename
raise
Expand Down
2 changes: 0 additions & 2 deletions yapf/yapflib/file_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
querying.
"""

import io
import os
import sys

from yapf.yapflib import py3compat

Expand Down
5 changes: 3 additions & 2 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def __eq__(self, other):
# Note: 'first_indent' is implicit in the stack. Also, we ignore 'previous',
# because it shouldn't have a bearing on this comparison. (I.e., it will
# report equal if 'next_token' does.)
return (self.next_token == other.next_token and self.column == other.column
and self.paren_level == other.paren_level and
return (self.next_token == other.next_token and
self.column == other.column and
self.paren_level == other.paren_level and
self.start_of_line_level == other.start_of_line_level and
self.lowest_level_on_line == other.lowest_level_on_line and
(self.ignore_stack_for_comparison or
Expand Down
4 changes: 2 additions & 2 deletions yapf/yapflib/py3compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.
"""Utilities for Python2 / Python3 compatibility."""

import io
import sys

PY3 = sys.version_info[0] == 3


if PY3:
import io
StringIO = io.StringIO
BytesIO = io.BytesIO

Expand All @@ -40,7 +40,6 @@
import cStringIO
StringIO = BytesIO = cStringIO.StringIO

import io
open_with_encoding = io.open

range = xrange
Expand All @@ -61,6 +60,7 @@ def EncodeAndWriteToStdout(s, encoding):
Arguments:
s: (string) The string to encode.
encoding: (string) The encoding of the string.
"""
if PY3:
sys.stdout.buffer.write(codecs.encode(s, encoding))
Expand Down
3 changes: 1 addition & 2 deletions yapf/yapflib/pytree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from lib2to3.pgen2 import driver
from lib2to3.pgen2 import parse
from lib2to3.pgen2 import token
from lib2to3.pgen2 import tokenize

# TODO(eliben): We may want to get rid of this filtering at some point once we
# have a better understanding of what information we need from the tree. Then,
Expand Down Expand Up @@ -110,7 +109,7 @@ def ParseCodeToTree(code):
try:
ast.parse(code)
except SyntaxError as e:
raise(e)
raise e
else:
raise
return _WrapEndMarker(tree)
Expand Down
4 changes: 3 additions & 1 deletion yapf/yapflib/reformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def Reformat(uwlines, verify=True):
while state.next_token:
next_token_lineno = state.next_token.lineno
prev_token = state.next_token.previous_token
prev_token_lineno = prev_token.lineno if prev_token else next_token_lineno
prev_token_lineno = (
prev_token.lineno if prev_token else next_token_lineno
)
if prev_token.is_continuation:
newline = False
else:
Expand Down
3 changes: 1 addition & 2 deletions yapf/yapflib/split_penalty.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def Visit_trailer(self, node): # pylint: disable=invalid-name
if node.children[0].value == '.':
self._SetUnbreakableOnChildren(node, num_children=len(node.children))
elif node.children[0].value == '[':
for child in node.children:
self._SetExpressionPenalty(node, SUBSCRIPT_LIST)
self._SetExpressionPenalty(node, SUBSCRIPT_LIST)
self._SetUnbreakable(node.children[0])
self._SetUnbreakable(node.children[-1])
elif len(node.children) == 2:
Expand Down
4 changes: 2 additions & 2 deletions yapf/yapflib/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def method():
SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT=textwrap.dedent("""\
The penalty incurred by adding a line split to the unwrapped line. The
more line splits added the higher the penalty."""),
#BASED_ON_STYLE='Which predefined style this style is based on',
# BASED_ON_STYLE='Which predefined style this style is based on',
)


def CreatePEP8Style():
return dict(
ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT = True,
ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT=True,
COLUMN_LIMIT=79,
I18N_COMMENT='',
I18N_FUNCTION_CALL='',
Expand Down
1 change: 0 additions & 1 deletion yapf/yapflib/yapf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"""

import difflib
import io
import logging
import re
import sys
Expand Down
4 changes: 2 additions & 2 deletions yapftests/file_resources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BufferedByteStream(object):
def __init__(self):
self.stream = py3compat.BytesIO()

def getvalue(self):
def getvalue(self): # pylint: disable=invalid-name
return self.stream.getvalue().decode('utf-8')

@property
Expand Down Expand Up @@ -78,7 +78,7 @@ def testWriteToStdout(self):
self.assertEqual(stream.getvalue(), s)

def testWriteEncodedToStdout(self):
s = '\ufeff# -*- coding: utf-8 -*-\nresult = "passed"\n'
s = '\ufeff# -*- coding: utf-8 -*-\nresult = "passed"\n' # pylint: disable=anomalous-unicode-escape-in-string
stream = BufferedByteStream() if py3compat.PY3 else py3compat.StringIO()
with stdout_redirector(stream):
file_resources.WriteReformattedCode(None, s,
Expand Down
2 changes: 1 addition & 1 deletion yapftests/yapf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class BadInputTest(unittest.TestCase):
"""Test yapf's behaviour when passed bad input."""

def testBadSyntax(self):
code = " a = 1\n"
code = ' a = 1\n'
self.assertRaises(SyntaxError, yapf_api.FormatCode, code)


Expand Down

0 comments on commit ffcbff1

Please sign in to comment.