Skip to content

Commit

Permalink
Fix pylint/black integration quirks
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed May 16, 2023
1 parent f2b3d8a commit a5db4dd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
13 changes: 7 additions & 6 deletions src/python/grpcio/grpc/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ def result(
raise self

def exception(
self, timeout: Optional[float] = None
) -> Optional[Exception]: # pylint: disable=unused-argument
self, timeout: Optional[float] = None # pylint: disable=unused-argument
) -> Optional[Exception]:
"""See grpc.Future.exception."""
return self

Expand All @@ -441,8 +441,10 @@ def traceback(
return sys.exc_info()[2]

def add_done_callback(
self, fn: Callable[[grpc.Future], None], timeout: Optional[float] = None
) -> None: # pylint: disable=unused-argument
self,
fn: Callable[[grpc.Future], None],
timeout: Optional[float] = None, # pylint: disable=unused-argument
) -> None:
"""See grpc.Future.add_done_callback."""
fn(self)

Expand Down Expand Up @@ -1805,8 +1807,7 @@ def _poll_connectivity(
]
)
callbacks = tuple(
callback
for callback, unused_but_known_to_be_none_connectivity in state.callbacks_and_connectivities
callback for callback, _ in state.callbacks_and_connectivities
)
for callback_and_connectivity in state.callbacks_and_connectivities:
callback_and_connectivity[1] = state.connectivity
Expand Down
2 changes: 1 addition & 1 deletion src/python/grpcio/grpc/aio/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
if sys.version_info[1] < 7:

def _all_tasks() -> Iterable[asyncio.Task]:
return asyncio.Task.all_tasks()
return asyncio.Task.all_tasks() # pylint: disable=no-member

else:

Expand Down
12 changes: 6 additions & 6 deletions src/python/grpcio_tests/tests/qps/worker_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def __init__(self, server_port=None):
self._snapshotter = Snapshotter()

def RunServer(self, request_iterator, context):
config = next(
request_iterator
).setup # pylint: disable=stop-iteration-return
# pylint: disable=stop-iteration-return
config = next(request_iterator).setup
# pylint: enable=stop-iteration-return
server, port = self._create_server(config)
cores = multiprocessing.cpu_count()
server.start()
Expand Down Expand Up @@ -159,9 +159,9 @@ def _create_server(self, config):
return (server, port)

def RunClient(self, request_iterator, context):
config = next(
request_iterator
).setup # pylint: disable=stop-iteration-return
# pylint: disable=stop-iteration-return
config = next(request_iterator).setup
# pylint: enable=stop-iteration-return
client_runners = []
qps_data = histogram.Histogram(
config.histogram_params.resolution,
Expand Down
5 changes: 4 additions & 1 deletion tools/distrib/pylint_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ PYTHON=$VIRTUALENV/bin/python
$PYTHON -m pip install --upgrade pip==19.3.1

# TODO(https://github.com/grpc/grpc/issues/23394): Update Pylint.
$PYTHON -m pip install --upgrade astroid==2.3.3 pylint==2.2.2 "isort>=4.3.0,<5.0.0"
$PYTHON -m pip install --upgrade astroid==2.3.3 \
pylint==2.2.2 \
toml==0.10.2 \
"isort>=4.3.0,<5.0.0"

EXIT=0
for dir in "${DIRS[@]}"; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def exists_forwarding_rule(self, src_port) -> bool:
'(loadBalancingScheme eq "INTERNAL_SELF_MANAGED")'
)
return self._exists_resource(
self.api.globalForwardingRules(), filter=filter_str
self.api.globalForwardingRules(), resource_filter=filter_str
)

def delete_forwarding_rule(self, name):
Expand Down Expand Up @@ -460,10 +460,10 @@ def _get_resource(
return self.GcpResource(resp["name"], resp["selfLink"])

def _exists_resource(
self, collection: discovery.Resource, filter: str
) -> bool: # pylint: disable=redefined-builtin
self, collection: discovery.Resource, resource_filter: str
) -> bool:
resp = collection.list(
project=self.project, filter=filter, maxResults=1
project=self.project, filter=resource_filter, maxResults=1
).execute(num_retries=self._GCP_API_RETRIES)
if "kind" not in resp:
# TODO(sergiitk): better error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ def _replace_binding(
new_bindings = set(policy.bindings)
new_bindings.discard(binding)
new_bindings.add(new_binding)
return dataclasses.replace(
policy, bindings=frozenset(new_bindings)
) # pylint: disable=too-many-function-args
# pylint: disable=too-many-function-args # No idea why pylint is like that.
return dataclasses.replace(policy, bindings=frozenset(new_bindings))


@dataclasses.dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,16 @@ def _cleanup(cls, cleanup_all: bool = False):
def _fetch_and_check_xds_config(self):
# TODO(lidiz) find another way to store last seen xDS config
# Cleanup state for this attempt
self._xds_json_config = (
None # pylint: disable=attribute-defined-outside-init
)
# pylint: disable=attribute-defined-outside-init
self._xds_json_config = None
# Fetch client config
config = self.test_client.csds.fetch_client_status(
log_level=logging.INFO
)
self.assertIsNotNone(config)
# Found client config, test it.
self._xds_json_config = json_format.MessageToDict(
config
) # pylint: disable=attribute-defined-outside-init
self._xds_json_config = json_format.MessageToDict(config)
# pylint: enable=attribute-defined-outside-init
# Execute the child class provided validation logic
self.xds_config_validate(DumpedXdsConfig(self._xds_json_config))

Expand Down

0 comments on commit a5db4dd

Please sign in to comment.