From 90798ab199e57a7d0846b7d5dd3d902b1c4056f2 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Wed, 22 Feb 2017 18:56:55 +0000 Subject: [PATCH] Fix and enable no-member lint --- .pylintrc | 3 +-- src/python/grpcio/grpc/_channel.py | 7 +++---- src/python/grpcio/grpc/_common.py | 4 ++-- src/python/grpcio/grpc/_server.py | 21 ++++++++++----------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.pylintrc b/.pylintrc index 1682488cb4a..da2081b87e1 100644 --- a/.pylintrc +++ b/.pylintrc @@ -30,6 +30,5 @@ #TODO: Enable too-many-nested-blocks #TODO: Enable super-init-not-called #TODO: Enable no-self-use -#TODO: Enable no-member -disable=missing-docstring,too-few-public-methods,too-many-arguments,no-init,duplicate-code,invalid-name,suppressed-message,locally-disabled,protected-access,no-name-in-module,unused-argument,fixme,wrong-import-order,no-value-for-parameter,cyclic-import,unused-variable,redefined-outer-name,unused-import,too-many-instance-attributes,broad-except,too-many-locals,too-many-lines,redefined-variable-type,next-method-called,import-error,useless-else-on-loop,too-many-return-statements,too-many-nested-blocks,super-init-not-called,no-self-use,no-member +disable=missing-docstring,too-few-public-methods,too-many-arguments,no-init,duplicate-code,invalid-name,suppressed-message,locally-disabled,protected-access,no-name-in-module,unused-argument,fixme,wrong-import-order,no-value-for-parameter,cyclic-import,unused-variable,redefined-outer-name,unused-import,too-many-instance-attributes,broad-except,too-many-locals,too-many-lines,redefined-variable-type,next-method-called,import-error,useless-else-on-loop,too-many-return-statements,too-many-nested-blocks,super-init-not-called,no-self-use diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index 26d93faf752..e602f39aeb0 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -43,7 +43,6 @@ _USER_AGENT = 'Python-gRPC-{}'.format(_grpcio_metadata.__version__) _EMPTY_FLAGS = 0 _INFINITE_FUTURE = cygrpc.Timespec(float('+inf')) -_EMPTY_METADATA = cygrpc.Metadata(()) _UNARY_UNARY_INITIAL_DUE = (cygrpc.OperationType.send_initial_metadata, cygrpc.OperationType.send_message, @@ -138,8 +137,8 @@ def _abort(state, code, details): state.code = code state.details = details if state.initial_metadata is None: - state.initial_metadata = _EMPTY_METADATA - state.trailing_metadata = _EMPTY_METADATA + state.initial_metadata = _common.EMPTY_METADATA + state.trailing_metadata = _common.EMPTY_METADATA def _handle_event(event, state, response_deserializer): @@ -435,7 +434,7 @@ def _start_unary_request(request, timeout, request_serializer): deadline, deadline_timespec = _deadline(timeout) serialized_request = _common.serialize(request, request_serializer) if serialized_request is None: - state = _RPCState((), _EMPTY_METADATA, _EMPTY_METADATA, + state = _RPCState((), _common.EMPTY_METADATA, _common.EMPTY_METADATA, grpc.StatusCode.INTERNAL, 'Exception serializing request!') rendezvous = _Rendezvous(state, None, None, deadline) diff --git a/src/python/grpcio/grpc/_common.py b/src/python/grpcio/grpc/_common.py index f9accd75a9f..6879e1780ba 100644 --- a/src/python/grpcio/grpc/_common.py +++ b/src/python/grpcio/grpc/_common.py @@ -37,7 +37,7 @@ import six import grpc from grpc._cython import cygrpc -_EMPTY_METADATA = cygrpc.Metadata(()) +EMPTY_METADATA = cygrpc.Metadata(()) CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY = { cygrpc.ConnectivityState.idle: @@ -107,7 +107,7 @@ def channel_args(options): def cygrpc_metadata(application_metadata): - return _EMPTY_METADATA if application_metadata is None else cygrpc.Metadata( + return EMPTY_METADATA if application_metadata is None else cygrpc.Metadata( cygrpc.Metadatum(encode(key), encode(value)) for key, value in application_metadata) diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index bf2743c16b9..b8e7ea17f70 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -57,7 +57,6 @@ _CLOSED = 'closed' _CANCELLED = 'cancelled' _EMPTY_FLAGS = 0 -_EMPTY_METADATA = cygrpc.Metadata(()) _UNEXPECTED_EXIT_SERVER_GRACE = 1.0 @@ -143,7 +142,7 @@ def _abort(state, call, code, details): effective_details = details if state.details is None else state.details if state.initial_metadata_allowed: operations = (cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), + _common.EMPTY_METADATA, _EMPTY_FLAGS), cygrpc.operation_send_status_from_server( _common.cygrpc_metadata(state.trailing_metadata), effective_code, effective_details, _EMPTY_FLAGS),) @@ -416,7 +415,7 @@ def _send_response(rpc_event, state, serialized_response): else: if state.initial_metadata_allowed: operations = (cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), + _common.EMPTY_METADATA, _EMPTY_FLAGS), cygrpc.operation_send_message(serialized_response, _EMPTY_FLAGS),) state.initial_metadata_allowed = False @@ -446,8 +445,8 @@ def _status(rpc_event, state, serialized_response): ] if state.initial_metadata_allowed: operations.append( - cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, - _EMPTY_FLAGS)) + cygrpc.operation_send_initial_metadata( + _common.EMPTY_METADATA, _EMPTY_FLAGS)) if serialized_response is not None: operations.append( cygrpc.operation_send_message(serialized_response, @@ -549,12 +548,12 @@ def _find_method_handler(rpc_event, generic_handlers): def _handle_unrecognized_method(rpc_event): - operations = ( - cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - _EMPTY_METADATA, cygrpc.StatusCode.unimplemented, - b'Method not found!', _EMPTY_FLAGS),) + operations = (cygrpc.operation_send_initial_metadata(_common.EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + _common.EMPTY_METADATA, cygrpc.StatusCode.unimplemented, + b'Method not found!', _EMPTY_FLAGS),) rpc_state = _RPCState() rpc_event.operation_call.start_server_batch( operations, lambda ignored_event: (rpc_state, (),))