Skip to content

Commit

Permalink
Merge pull request grpc#15682 from mehrdada/bump-pylint
Browse files Browse the repository at this point in the history
Bump pylint to 1.9.2
  • Loading branch information
mehrdada committed Jun 8, 2018
2 parents ab8642d + d6547ea commit 92a0635
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 240 deletions.
11 changes: 9 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ disable=
# TODO(https://github.com/grpc/grpc/issues/261): Maybe we could have
# this one if we extracted just a few more helper functions...
too-many-nested-blocks,
# NOTE(nathaniel): I have disputed the premise of this inspection from
# the beginning and will continue to do so until it goes away for good.
# TODO(https://github.com/grpc/grpc/issues/261): Disable unnecessary
# super-init requirement for abstract class implementations for now.
super-init-not-called,
# NOTE(nathaniel): A single statement that always returns program
# control is better than two statements the first of which sometimes
# returns program control and the second of which always returns
# program control. Probably generally, but definitely in the cases of
# if:/else: and for:/else:.
useless-else-on-loop,
no-else-return,
11 changes: 9 additions & 2 deletions .pylintrc-tests
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ disable=
# TODO(https://github.com/grpc/grpc/issues/261): Maybe we could have
# this one if we extracted just a few more helper functions...
too-many-nested-blocks,
# NOTE(nathaniel): I have disputed the premise of this inspection from
# the beginning and will continue to do so until it goes away for good.
# TODO(https://github.com/grpc/grpc/issues/261): Disable unnecessary
# super-init requirement for abstract class implementations for now.
super-init-not-called,
# NOTE(nathaniel): A single statement that always returns program
# control is better than two statements the first of which sometimes
# returns program control and the second of which always returns
# program control. Probably generally, but definitely in the cases of
# if:/else: and for:/else:.
useless-else-on-loop,
no-else-return,
10 changes: 5 additions & 5 deletions src/python/grpcio/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ def ssl_server_credentials(private_key_certificate_chain_pairs,
A ServerCredentials for use with an SSL-enabled Server. Typically, this
object is an argument to add_secure_port() method during server setup.
"""
if len(private_key_certificate_chain_pairs) == 0:
if not private_key_certificate_chain_pairs:
raise ValueError(
'At least one private key-certificate chain pair is required!')
elif require_client_auth and root_certificates is None:
Expand Down Expand Up @@ -1512,15 +1512,15 @@ def ssl_server_certificate_configuration(private_key_certificate_chain_pairs,
A ServerCertificateConfiguration that can be returned in the certificate
configuration fetching callback.
"""
if len(private_key_certificate_chain_pairs) == 0:
raise ValueError(
'At least one private key-certificate chain pair is required!')
else:
if private_key_certificate_chain_pairs:
return ServerCertificateConfiguration(
_cygrpc.server_certificate_config_ssl(root_certificates, [
_cygrpc.SslPemKeyCertPair(key, pem)
for key, pem in private_key_certificate_chain_pairs
]))
else:
raise ValueError(
'At least one private key-certificate chain pair is required!')


def dynamic_ssl_server_credentials(initial_certificate_configuration,
Expand Down
7 changes: 2 additions & 5 deletions src/python/grpcio/grpc/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def consume_request_iterator(): # pylint: disable=too-many-branches
with state.condition:
if state.code is None and not state.cancelled:
if serialized_request is None:
code = grpc.StatusCode.INTERNAL # pylint: disable=redefined-variable-type
code = grpc.StatusCode.INTERNAL
details = 'Exception serializing request!'
call.cancel(
_common.STATUS_CODE_TO_CYGRPC_STATUS_CODE[code],
Expand Down Expand Up @@ -813,10 +813,7 @@ def _poll_connectivity(state, channel, initial_try_to_connect):
_common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[
connectivity])
if not state.delivering:
# NOTE(nathaniel): The field is only ever used as a
# sequence so it's fine that both lists and tuples are
# assigned to it.
callbacks = _deliveries(state) # pylint: disable=redefined-variable-type
callbacks = _deliveries(state)
if callbacks:
_spawn_delivery(state, callbacks)

Expand Down
17 changes: 13 additions & 4 deletions src/python/grpcio/grpc/_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def cancel(self):
def cancelled(self):
return False

def is_active(self):
return False

def time_remaining(self):
return None

def running(self):
return False

Expand All @@ -115,6 +121,9 @@ def exception(self, ignored_timeout=None):
def traceback(self, ignored_timeout=None):
return self._traceback

def add_callback(self, callback):
return False

def add_done_callback(self, fn):
fn(self)

Expand Down Expand Up @@ -288,11 +297,11 @@ def __init__(self, channel, interceptor):
self._channel = channel
self._interceptor = interceptor

def subscribe(self, *args, **kwargs):
self._channel.subscribe(*args, **kwargs)
def subscribe(self, callback, try_to_connect=False):
self._channel.subscribe(callback, try_to_connect=try_to_connect)

def unsubscribe(self, *args, **kwargs):
self._channel.unsubscribe(*args, **kwargs)
def unsubscribe(self, callback):
self._channel.unsubscribe(callback)

def unary_unary(self,
method,
Expand Down
2 changes: 2 additions & 0 deletions src/python/grpcio/grpc/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ def _look_for_request(self):
self._state.request = None
return request

raise AssertionError() # should never run

def _next(self):
with self._state.condition:
self._raise_or_start_receive_message()
Expand Down
2 changes: 2 additions & 0 deletions src/python/grpcio/grpc/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def cancel(self):
callable_util.call_logging_exceptions(
done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self)

return True

def cancelled(self):
with self._condition:
return self._cancelled
Expand Down
1 change: 1 addition & 0 deletions src/python/grpcio/grpc/beta/_server_adaptations.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def _simple_method_handler(implementation, request_deserializer,
response_serializer, None, None, None,
_adapt_stream_stream_event(
implementation.stream_stream_event))
raise ValueError()


def _flatten_method_pair_map(method_pair_map):
Expand Down
2 changes: 2 additions & 0 deletions src/python/grpcio/grpc/beta/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def cancel(self):
callable_util.call_logging_exceptions(
done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self)

return True

def cancelled(self):
with self._condition:
return self._cancelled
Expand Down
8 changes: 4 additions & 4 deletions src/python/grpcio/grpc/framework/foundation/stream_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ def __init__(self):
self._values = []
self._active = True

def consume(self, stock_reply):
def consume(self, value):
with self._condition:
if self._active:
self._values.append(stock_reply)
self._values.append(value)
self._condition.notify()

def terminate(self):
with self._condition:
self._active = False
self._condition.notify()

def consume_and_terminate(self, stock_reply):
def consume_and_terminate(self, value):
with self._condition:
if self._active:
self._values.append(stock_reply)
self._values.append(value)
self._active = False
self._condition.notify()

Expand Down
2 changes: 1 addition & 1 deletion src/python/grpcio_testing/grpc_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"""Objects for use in testing gRPC Python-using application code."""

import abc
import six

from google.protobuf import descriptor
import six

import grpc

Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_testing/grpc_testing/_server/_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def send_termination(self, trailing_metadata, code, details):
self._expiration_future.cancel()
self._condition.notify_all()

def add_termination_callback(self, termination_callback):
def add_termination_callback(self, callback):
with self._condition:
if self._code is None:
self._termination_callbacks.append(termination_callback)
self._termination_callbacks.append(callback)
return True
else:
return False
Expand Down
11 changes: 6 additions & 5 deletions src/python/grpcio_tests/tests/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ def loadTestsFromNames(self, names, module=None):
# measure unnecessarily suffers)
coverage_context = coverage.Coverage(data_suffix=True)
coverage_context.start()
modules = [importlib.import_module(name) for name in names]
for module in modules:
self.visit_module(module)
for module in modules:
imported_modules = tuple(
importlib.import_module(name) for name in names)
for imported_module in imported_modules:
self.visit_module(imported_module)
for imported_module in imported_modules:
try:
package_paths = module.__path__
package_paths = imported_module.__path__
except AttributeError:
continue
self.walk_packages(package_paths)
Expand Down
41 changes: 15 additions & 26 deletions src/python/grpcio_tests/tests/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,26 @@ def startTestRun(self):
super(AugmentedResult, self).startTestRun()
self.cases = dict()

def stopTestRun(self):
"""See unittest.TestResult.stopTestRun."""
super(AugmentedResult, self).stopTestRun()

def startTest(self, test):
"""See unittest.TestResult.startTest."""
super(AugmentedResult, self).startTest(test)
case_id = self.id_map(test)
self.cases[case_id] = CaseResult(
id=case_id, name=test.id(), kind=CaseResult.Kind.RUNNING)

def addError(self, test, error):
def addError(self, test, err):
"""See unittest.TestResult.addError."""
super(AugmentedResult, self).addError(test, error)
super(AugmentedResult, self).addError(test, err)
case_id = self.id_map(test)
self.cases[case_id] = self.cases[case_id].updated(
kind=CaseResult.Kind.ERROR, traceback=error)
kind=CaseResult.Kind.ERROR, traceback=err)

def addFailure(self, test, error):
def addFailure(self, test, err):
"""See unittest.TestResult.addFailure."""
super(AugmentedResult, self).addFailure(test, error)
super(AugmentedResult, self).addFailure(test, err)
case_id = self.id_map(test)
self.cases[case_id] = self.cases[case_id].updated(
kind=CaseResult.Kind.FAILURE, traceback=error)
kind=CaseResult.Kind.FAILURE, traceback=err)

def addSuccess(self, test):
"""See unittest.TestResult.addSuccess."""
Expand All @@ -183,12 +179,12 @@ def addSkip(self, test, reason):
self.cases[case_id] = self.cases[case_id].updated(
kind=CaseResult.Kind.SKIP, skip_reason=reason)

def addExpectedFailure(self, test, error):
def addExpectedFailure(self, test, err):
"""See unittest.TestResult.addExpectedFailure."""
super(AugmentedResult, self).addExpectedFailure(test, error)
super(AugmentedResult, self).addExpectedFailure(test, err)
case_id = self.id_map(test)
self.cases[case_id] = self.cases[case_id].updated(
kind=CaseResult.Kind.EXPECTED_FAILURE, traceback=error)
kind=CaseResult.Kind.EXPECTED_FAILURE, traceback=err)

def addUnexpectedSuccess(self, test):
"""See unittest.TestResult.addUnexpectedSuccess."""
Expand Down Expand Up @@ -249,13 +245,6 @@ def stopTest(self, test):
self.coverage_context.save()
self.coverage_context = None

def stopTestRun(self):
"""See unittest.TestResult.stopTestRun."""
super(CoverageResult, self).stopTestRun()
# TODO(atash): Dig deeper into why the following line fails to properly
# combine coverage data from the Cython plugin.
#coverage.Coverage().combine()


class _Colors(object):
"""Namespaced constants for terminal color magic numbers."""
Expand Down Expand Up @@ -295,16 +284,16 @@ def stopTestRun(self):
self.out.write(summary(self))
self.out.flush()

def addError(self, test, error):
def addError(self, test, err):
"""See unittest.TestResult.addError."""
super(TerminalResult, self).addError(test, error)
super(TerminalResult, self).addError(test, err)
self.out.write(
_Colors.FAIL + 'ERROR {}\n'.format(test.id()) + _Colors.END)
self.out.flush()

def addFailure(self, test, error):
def addFailure(self, test, err):
"""See unittest.TestResult.addFailure."""
super(TerminalResult, self).addFailure(test, error)
super(TerminalResult, self).addFailure(test, err)
self.out.write(
_Colors.FAIL + 'FAILURE {}\n'.format(test.id()) + _Colors.END)
self.out.flush()
Expand All @@ -323,9 +312,9 @@ def addSkip(self, test, reason):
_Colors.INFO + 'SKIP {}\n'.format(test.id()) + _Colors.END)
self.out.flush()

def addExpectedFailure(self, test, error):
def addExpectedFailure(self, test, err):
"""See unittest.TestResult.addExpectedFailure."""
super(TerminalResult, self).addExpectedFailure(test, error)
super(TerminalResult, self).addExpectedFailure(test, err)
self.out.write(
_Colors.INFO + 'FAILURE_OK {}\n'.format(test.id()) + _Colors.END)
self.out.flush()
Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_tests/tests/interop/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def _large_unary_common_behavior(stub, fill_username, fill_oauth_scope,
def _empty_unary(stub):
response = stub.EmptyCall(empty_pb2.Empty())
if not isinstance(response, empty_pb2.Empty):
raise TypeError('response is of type "%s", not empty_pb2.Empty!',
type(response))
raise TypeError(
'response is of type "%s", not empty_pb2.Empty!' % type(response))


def _large_unary(stub):
Expand Down
13 changes: 0 additions & 13 deletions src/python/grpcio_tests/tests/unit/_junkdrawer/__init__.py

This file was deleted.

Loading

0 comments on commit 92a0635

Please sign in to comment.