Skip to content

Commit

Permalink
Merge pull request #152 from cherba/lint
Browse files Browse the repository at this point in the history
Fix new lint warnings/errors.
  • Loading branch information
vilasj authored Apr 20, 2017
2 parents fa2ea1d + 77f3625 commit 49fe50e
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 64 deletions.
19 changes: 7 additions & 12 deletions apitools/base/protorpclite/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def __str__(self):
LAST_RESERVED_FIELD_NUMBER = 19999


# pylint: disable=no-value-for-parameter
class _DefinitionClass(type):
"""Base meta-class used for definition meta-classes.
Expand Down Expand Up @@ -250,8 +251,7 @@ class MyMessage(Message):
outer_definition_name = cls.outer_definition_name()
if outer_definition_name is None:
return six.text_type(cls.__name__)
else:
return u'%s.%s' % (outer_definition_name, cls.__name__)
return u'%s.%s' % (outer_definition_name, cls.__name__)

def outer_definition_name(cls):
"""Helper method for creating outer definition name.
Expand All @@ -264,8 +264,7 @@ def outer_definition_name(cls):
outer_definition = cls.message_definition()
if not outer_definition:
return util.get_package_for_module(cls.__module__)
else:
return outer_definition.definition_name()
return outer_definition.definition_name()

def definition_package(cls):
"""Helper method for creating creating the package of a definition.
Expand All @@ -276,8 +275,7 @@ def definition_package(cls):
outer_definition = cls.message_definition()
if not outer_definition:
return util.get_package_for_module(cls.__module__)
else:
return outer_definition.definition_package()
return outer_definition.definition_package()


class _EnumClass(_DefinitionClass):
Expand Down Expand Up @@ -1103,8 +1101,7 @@ def __getstate__(self):
message_class = self.__field.message_definition()
if message_class is None:
return self.__field, None, None
else:
return None, message_class, self.__field.number
return None, message_class, self.__field.number

def __setstate__(self, state):
"""Enable unpickling.
Expand Down Expand Up @@ -1299,8 +1296,7 @@ def __set__(self, message_instance, value):
if self.repeated:
value = FieldList(self, value)
else:
value = ( # pylint: disable=redefined-variable-type
self.validate(value))
value = self.validate(value)
message_instance._Message__tags[self.number] = value

def __get__(self, message_instance, message_class):
Expand All @@ -1310,8 +1306,7 @@ def __get__(self, message_instance, message_class):
result = message_instance._Message__tags.get(self.number)
if result is None:
return self.default
else:
return result
return result

def validate_element(self, value):
"""Validate single element of field.
Expand Down
2 changes: 0 additions & 2 deletions apitools/base/protorpclite/messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ def testValidateCastingElement(self):
field = messages.FloatField(1)
self.assertEquals(type(field.validate_element(12)), float)
self.assertEquals(type(field.validate_element(12.0)), float)
# pylint: disable=redefined-variable-type
field = messages.IntegerField(1)
self.assertEquals(type(field.validate_element(12)), int)
self.assertRaises(messages.ValidationError,
Expand Down Expand Up @@ -1659,7 +1658,6 @@ class Message(messages.Message):
messages.ValidationError,
"Field val is repeated. Found: <SubMessage>",
setattr, message, 'val', SubMessage())
# pylint: disable=redefined-variable-type
message.val = [SubMessage()]
message_field.validate(message)

Expand Down
4 changes: 2 additions & 2 deletions apitools/base/protorpclite/protojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def default(self, value):
unknown_key)
result[unknown_key] = unrecognized_field
return result
else:
return super(MessageJSONEncoder, self).default(value)

return super(MessageJSONEncoder, self).default(value)


class ProtoJson(object):
Expand Down
3 changes: 1 addition & 2 deletions apitools/base/protorpclite/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,5 +641,4 @@ def get_module_name(module_attribute):
module_file = inspect.getfile(module_attribute)
default = os.path.basename(module_file).split('.')[0]
return default
else:
return module_attribute.__module__
return module_attribute.__module__
3 changes: 1 addition & 2 deletions apitools/base/protorpclite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ def get_package_for_module(module):
split_name = os.path.splitext(base_name)
if len(split_name) == 1:
return six.text_type(base_name)
else:
return u'.'.join(split_name[:-1])
return u'.'.join(split_name[:-1])

return six.text_type(module.__name__)

Expand Down
34 changes: 17 additions & 17 deletions apitools/base/py/app2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

"""Appcommands-compatible command class with extra fixins."""
from __future__ import absolute_import
from __future__ import print_function

import cmd
Expand All @@ -25,11 +26,11 @@
import traceback
import types

import six

import gflags as flags
from google.apputils import app
from google.apputils import appcommands
import gflags as flags
import six


__all__ = [
'NewCmd',
Expand All @@ -50,8 +51,7 @@ def _SafeMakeAscii(s):
return s.encode('ascii')
elif isinstance(s, str):
return s.decode('ascii')
else:
return six.text_type(s).encode('ascii', 'backslashreplace')
return six.text_type(s).encode('ascii', 'backslashreplace')


class NewCmd(appcommands.Cmd):
Expand Down Expand Up @@ -91,8 +91,7 @@ def __getattr__(self, name):
def _GetFlag(self, flagname):
if flagname in self._command_flags:
return self._command_flags[flagname]
else:
return None
return None

def Run(self, argv):
"""Run this command.
Expand Down Expand Up @@ -129,8 +128,7 @@ def Run(self, argv):

if self._debug_mode:
return self.RunDebug(args, {})
else:
return self.RunSafely(args, {})
return self.RunSafely(args, {})

def RunCmdLoop(self, argv):
"""Hook for use in cmd.Cmd-based command shells."""
Expand Down Expand Up @@ -220,7 +218,7 @@ def __init__(self, commands, prompt):
def last_return_code(self):
return self._last_return_code

def _set_prompt(self):
def _set_prompt(self): # pylint: disable=invalid-name
self.prompt = self._default_prompt

def do_EOF(self, *unused_args): # pylint: disable=invalid-name
Expand Down Expand Up @@ -306,11 +304,14 @@ def get_names(self):
names.remove('do_EOF')
return names

def do_help(self, command_name):
def do_help(self, arg):
"""Print the help for command_name (if present) or general help."""

command_name = arg

# TODO(craigcitro): Add command-specific flags.
def FormatOneCmd(name, command, command_names):
"""Format one command."""
indent_size = appcommands.GetMaxCommandLength() + 3
if len(command_names) > 1:
indent = ' ' * indent_size
Expand All @@ -322,12 +323,11 @@ def FormatOneCmd(name, command, command_names):
first_line = '%-*s%s' % (indent_size,
name + ':', first_help_line)
return '\n'.join((first_line, rest))
else:
default_indent = ' '
return '\n' + flags.TextWrap(
command.CommandGetHelp('', cmd_names=command_names),
indent=default_indent,
firstline_indent=default_indent) + '\n'
default_indent = ' '
return '\n' + flags.TextWrap(
command.CommandGetHelp('', cmd_names=command_names),
indent=default_indent,
firstline_indent=default_indent) + '\n'

if not command_name:
print('\nHelp for commands:\n')
Expand Down
10 changes: 5 additions & 5 deletions apitools/base/py/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def user_agent(self):
@property
def _default_global_params(self):
if self.__default_global_params is None:
# pylint: disable=not-callable
self.__default_global_params = self.params_type()
return self.__default_global_params

Expand Down Expand Up @@ -605,11 +606,10 @@ def __ProcessHttpResponse(self, method_config, http_response, request):
request_url=http_response.request_url)
if self.__client.response_type_model == 'json':
return http_response.content
else:
response_type = _LoadClass(method_config.response_type_name,
self.__client.MESSAGES_MODULE)
return self.__client.DeserializeMessage(
response_type, http_response.content)
response_type = _LoadClass(method_config.response_type_name,
self.__client.MESSAGES_MODULE)
return self.__client.DeserializeMessage(
response_type, http_response.content)

def __SetBaseHeaders(self, http_request, client):
"""Fill in the basic headers on http_request."""
Expand Down
10 changes: 5 additions & 5 deletions apitools/base/py/base_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"""Base script for generated CLI."""

from __future__ import absolute_import

import atexit
import code
import logging
Expand All @@ -24,8 +26,8 @@
import rlcompleter
import sys

from google.apputils import appcommands
import gflags as flags
from google.apputils import appcommands

from apitools.base.py import encoding
from apitools.base.py import exceptions
Expand Down Expand Up @@ -97,15 +99,13 @@ def _callable_postfix(self, val, word):
if ('(' in readline.get_line_buffer() or
not callable(val)):
return word
else:
return word + '('
return word + '('

def complete(self, text, state):
if not readline.get_line_buffer().strip():
if not state:
return ' '
else:
return None
return None
return rlcompleter.Completer.complete(self, text, state)


Expand Down
3 changes: 1 addition & 2 deletions apitools/base/py/batch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def CheckRequest(_, request, **unused_kwds):
self.assertEqual(expected_request.http_method, request.http_method)
if isinstance(response, list):
return response.pop(0)
else:
return response
return response

mock_request.side_effect = CheckRequest

Expand Down
1 change: 1 addition & 0 deletions apitools/base/py/credentials_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def GetInstanceScopes(self):
return util.NormalizeScopes(scope.strip()
for scope in response.readlines())

# pylint: disable=arguments-differ
def _refresh(self, do_request):
"""Refresh self.access_token.
Expand Down
1 change: 0 additions & 1 deletion apitools/base/py/encoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def testNestedIncludeFields(self):
'{"nested": {"additional_properties": []}}',
encoding.MessageToJson(
msg, include_fields=['nested.additional_properties']))
# pylint: disable=redefined-variable-type
msg = ExtraNestedMessage(nested=msg)
self.assertEqual(
'{"nested": {"nested": null}}',
Expand Down
3 changes: 1 addition & 2 deletions apitools/base/py/testing/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ def __call__(self, request, **unused_kwargs):
def _MakeMockedService(api_name, collection_name,
mock_client, service, real_service):
class MockedService(base_api.BaseApiService):
def __init__(self, real_client):
super(MockedService, self).__init__(real_client)
pass

for method in service.GetMethodsList():
real_method = None
Expand Down
14 changes: 5 additions & 9 deletions apitools/base/py/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ def total_size(self):
def __str__(self):
if not self.initialized:
return 'Download (uninitialized)'
else:
return 'Download with %d/%s bytes transferred from url %s' % (
self.progress, self.total_size, self.url)
return 'Download with %d/%s bytes transferred from url %s' % (
self.progress, self.total_size, self.url)

def ConfigureRequest(self, http_request, url_builder):
url_builder.query_params['alt'] = 'media'
Expand Down Expand Up @@ -648,9 +647,8 @@ def mime_type(self):
def __str__(self):
if not self.initialized:
return 'Upload (uninitialized)'
else:
return 'Upload with %d/%s bytes transferred for url %s' % (
self.progress, self.total_size or '???', self.url)
return 'Upload with %d/%s bytes transferred for url %s' % (
self.progress, self.total_size or '???', self.url)

@property
def strategy(self):
Expand Down Expand Up @@ -850,8 +848,7 @@ def InitializeUpload(self, http_request, http=None, client=None):
# go ahead and pump the bytes now.
if self.auto_transfer:
return self.StreamInChunks()
else:
return http_response
return http_response

def __GetLastByte(self, range_header):
_, _, end = range_header.partition('-')
Expand Down Expand Up @@ -992,7 +989,6 @@ def __SendChunk(self, start, additional_headers=None):
# https://code.google.com/p/httplib2/issues/detail?id=176 which can
# cause httplib2 to skip bytes on 401's for file objects.
# Rework this solution to be more general.
# pylint: disable=redefined-variable-type
body_stream = body_stream.read(self.chunksize)
else:
end = min(start + self.chunksize, self.total_size)
Expand Down
3 changes: 1 addition & 2 deletions apitools/gen/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ def __GetTypeInfo(self, attrs, name_hint):
entry_name_hint, items.get('items'), parent_name)
return TypeInfo(type_name=entry_type_name,
variant=messages.Variant.MESSAGE)
else:
return self.__GetTypeInfo(items, entry_name_hint)
return self.__GetTypeInfo(items, entry_name_hint)
elif type_name == 'any':
self.__AddImport('from %s import extra_types' %
self.__base_files_package)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
REQUIRED_PACKAGES = [
'httplib2>=0.8',
'oauth2client>=1.5.2,<4.0.0dev',
'setuptools>=18.5',
'setuptools==18.5',
'six>=1.9.0',
]

Expand Down

0 comments on commit 49fe50e

Please sign in to comment.