From 4af2d0a5e6b65a971bd726903cb01d4ca6437f13 Mon Sep 17 00:00:00 2001 From: Hendrik Makait Date: Thu, 4 Aug 2022 17:40:29 +0200 Subject: [PATCH] Miscellaneous `flake8-bugbear` issues (#6814) --- distributed/client.py | 4 ++-- distributed/comm/addressing.py | 9 ++++++--- distributed/tests/test_client.py | 4 ++-- distributed/utils.py | 2 +- distributed/worker.py | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/distributed/client.py b/distributed/client.py index cf7e06e009b..1a50d9e21cc 100644 --- a/distributed/client.py +++ b/distributed/client.py @@ -836,8 +836,8 @@ def __init__( elif isinstance(getattr(address, "scheduler_address", None), str): # It's a LocalCluster or LocalCluster-compatible object self.cluster = address - status = getattr(self.cluster, "status") - if status and status in [Status.closed, Status.closing]: + status = self.cluster.status + if status in (Status.closed, Status.closing): raise RuntimeError( f"Trying to connect to an already closed or closing Cluster {self.cluster}." ) diff --git a/distributed/comm/addressing.py b/distributed/comm/addressing.py index 6cc40a6a3cc..a4925660111 100644 --- a/distributed/comm/addressing.py +++ b/distributed/comm/addressing.py @@ -272,7 +272,10 @@ def address_from_user_args( # type: ignore[no-untyped-def] if security and security.require_encryption and not protocol: protocol = "tls" - if protocol and protocol.rstrip("://") == "inplace": + if protocol and protocol.endswith("://"): + protocol, _, _ = protocol.rpartition("://") + + if protocol == "inplace": if host or port or interface: raise ValueError( "Can not specify inproc protocol and host or port or interface" @@ -287,7 +290,7 @@ def address_from_user_args( # type: ignore[no-untyped-def] host = get_ip_interface(interface) if protocol and host and "://" not in host: - host = protocol.rstrip("://") + "://" + host + host = protocol + "://" + host if host or port: addr = uri_from_host_port(host, port, default_port) @@ -295,6 +298,6 @@ def address_from_user_args( # type: ignore[no-untyped-def] addr = "" if protocol: - addr = protocol.rstrip("://") + "://" + addr.split("://")[-1] + addr = protocol + "://" + addr.split("://")[-1] return addr diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index beb31235f51..df891cb48dc 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -3866,8 +3866,8 @@ def test_get_versions_sync(c): assert v["scheduler"] is not None assert v["client"] is not None assert len(v["workers"]) == 2 - for v in v["workers"].values(): - assert v is not None + for wv in v["workers"].values(): + assert wv is not None c.get_versions(check=True) # smoke test for versions diff --git a/distributed/utils.py b/distributed/utils.py index 1898d0982a1..b5b18ba3890 100644 --- a/distributed/utils.py +++ b/distributed/utils.py @@ -1227,7 +1227,7 @@ def command_has_keyword(cmd, k): except ImportError: raise ImportError("Module for command %s is not available" % cmd) - if isinstance(getattr(cmd, "main"), click.core.Command): + if isinstance(cmd.main, click.core.Command): cmd = cmd.main if isinstance(cmd, click.core.Command): cmd_params = { diff --git a/distributed/worker.py b/distributed/worker.py index 221e4fc6c29..0822c77775c 100644 --- a/distributed/worker.py +++ b/distributed/worker.py @@ -212,7 +212,7 @@ async def _force_close(self): await asyncio.wait_for(self.close(nanny=False, executor_wait=False), 30) except (KeyboardInterrupt, SystemExit): # pragma: nocover raise - except (Exception, BaseException): # pragma: nocover + except BaseException: # pragma: nocover # Worker is in a very broken state if closing fails. We need to shut down # immediately, to ensure things don't get even worse and this worker potentially # deadlocks the cluster.