Skip to content

Commit

Permalink
Remove unnecessary comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsource-autofix[bot] authored Apr 23, 2020
1 parent 1bfc966 commit 19a678e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions labthings/core/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand 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():
Expand All @@ -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):
Expand All @@ -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)
2 changes: 1 addition & 1 deletion labthings/server/labthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion labthings/server/spec/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_core_tasks_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 19a678e

Please sign in to comment.