From 19a678e07906a57eb90c7bfe95ad2bb2e638a2be Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2020 21:47:20 +0000 Subject: [PATCH] Remove unnecessary comprehension --- labthings/core/lock.py | 10 ++++------ labthings/server/labthing.py | 2 +- labthings/server/spec/utilities.py | 2 +- tests/test_core_tasks_pool.py | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/labthings/core/lock.py b/labthings/core/lock.py index ffa9991b..df0b02b2 100644 --- a/labthings/core/lock.py +++ b/labthings/core/lock.py @@ -83,10 +83,8 @@ def acquire(self, blocking=True, timeout=None): timeout = self.timeout lock_all = all( - [ - lock.acquire(blocking=blocking, timeout=timeout, _strict=False) + lock.acquire(blocking=blocking, timeout=timeout, _strict=False) for lock in self.locks - ] ) if not lock_all: @@ -103,7 +101,7 @@ def __exit__(self, *args): def release(self): # If not all child locks are owner by caller - if not all([owner is getcurrent() for owner in self._owner]): + if not all(owner is getcurrent() for owner in self._owner): raise RuntimeError("cannot release un-acquired lock") for lock in self.locks: if lock.locked(): @@ -115,7 +113,7 @@ def _emergency_release(self): lock.release() def locked(self): - return any([lock.locked() for lock in self.locks]) + return any(lock.locked() for lock in self.locks) @property def _owner(self): @@ -127,4 +125,4 @@ def _owner(self, new_owner): lock._owner = new_owner def _is_owned(self): - return all([lock._is_owned() for lock in self.locks]) + return all(lock._is_owned() for lock in self.locks) diff --git a/labthings/server/labthing.py b/labthings/server/labthing.py index 46ff5a2d..9458a6d8 100644 --- a/labthings/server/labthing.py +++ b/labthings/server/labthing.py @@ -233,7 +233,7 @@ def _complete_url(self, url_part, registration_prefix): blueprint. Generally speaking, BlueprintSetupState.url_prefix """ parts = [self.url_prefix, registration_prefix, url_part] - u = "".join([clean_url_string(part) for part in parts if part]) + u = "".join(clean_url_string(part) for part in parts if part) return u if u else "/" def add_view(self, resource, *urls, endpoint=None, **kwargs): diff --git a/labthings/server/spec/utilities.py b/labthings/server/spec/utilities.py index edc3a8a3..b31de239 100644 --- a/labthings/server/spec/utilities.py +++ b/labthings/server/spec/utilities.py @@ -28,7 +28,7 @@ def tag_spec(obj, tags, add_group: bool = True): obj.__apispec__["tags"] = set() if isinstance(tags, set) or isinstance(tags, list): - if not all([isinstance(e, str) for e in tags]): + if not all(isinstance(e, str) for e in tags): raise TypeError("All tags must be strings") obj.__apispec__["tags"] = obj.__apispec__["tags"].union(tags) elif isinstance(tags, str): diff --git a/tests/test_core_tasks_pool.py b/tests/test_core_tasks_pool.py index 902dd9f3..6c6e318c 100644 --- a/tests/test_core_tasks_pool.py +++ b/tests/test_core_tasks_pool.py @@ -50,15 +50,15 @@ def test_update_task_progress_main_thread(): def test_tasks_list(): - assert all([isinstance(task_obj, gevent.Greenlet) for task_obj in tasks.tasks()]) + assert all(isinstance(task_obj, gevent.Greenlet) for task_obj in tasks.tasks()) def test_tasks_dict(): assert all( - [isinstance(task_obj, gevent.Greenlet) for task_obj in tasks.to_dict().values()] + isinstance(task_obj, gevent.Greenlet) for task_obj in tasks.to_dict().values() ) - assert all([k == str(t.id) for k, t in tasks.to_dict().items()]) + assert all(k == str(t.id) for k, t in tasks.to_dict().items()) def test_task_states():