From d9df5b4e32a582e25ec0176174fed1fea5f8f4dc Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Mon, 15 Nov 2021 18:43:46 +0000 Subject: [PATCH 1/3] Sourcery suggested refactorings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sourcery refactored this code to make it cleaner and more readable. If you want Sourcery to review the full project or all new pull requests, add [Sourcery](https://github.com/sourcery-ai/sourcery) to your repo. We try to only open PRs that are helpful. If this isn't helpful or you have any feedback for us - please [let us know](mailto:github@sourcery.ai)! --- tcrudge/decorators.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tcrudge/decorators.py b/tcrudge/decorators.py index 13b5418..90e3bb2 100644 --- a/tcrudge/decorators.py +++ b/tcrudge/decorators.py @@ -13,11 +13,7 @@ async def func(self, *args, **kw): auth = await self.is_auth() if auth: roles = await self.get_roles() - valid_permission = False - for r in roles: - if r in items: - valid_permission = True - break + valid_permission = any(r in items for r in roles) if not valid_permission: await self.bad_permissions() return await f(self, *args, **kw) From 31be81f98153b314ed470b986fafbf60a421d73e Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Mon, 15 Nov 2021 18:44:38 +0000 Subject: [PATCH 2/3] Update handlers.py --- tcrudge/handlers.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tcrudge/handlers.py b/tcrudge/handlers.py index 8ca2156..685033c 100644 --- a/tcrudge/handlers.py +++ b/tcrudge/handlers.py @@ -568,12 +568,11 @@ async def _get_items(self, qs): items, total = await multi(awaitables) # Set total items number pagination['total'] = total + elif self.prefetch_queries: + items = await self.application.objects.prefetch(qs, + *self.prefetch_queries) else: - if self.prefetch_queries: - items = await self.application.objects.prefetch(qs, - *self.prefetch_queries) - else: - items = await self.application.objects.execute(qs) + items = await self.application.objects.execute(qs) except (peewee.DataError, ValueError) as e: # Bad parameters raise HTTPError( From 8f43fc695a9522a7e2bdbe0cfc795b513605903d Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Mon, 15 Nov 2021 18:45:18 +0000 Subject: [PATCH 3/3] Update schema.py --- tcrudge/utils/schema.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tcrudge/utils/schema.py b/tcrudge/utils/schema.py index 2146936..5bb12f2 100644 --- a/tcrudge/utils/schema.py +++ b/tcrudge/utils/schema.py @@ -218,10 +218,10 @@ def _get_properties(self, recurse=True): if not recurse: return dict(self._properties) - properties = {} - for prop, subschema in self._properties.items(): - properties[prop] = subschema.to_dict() - return properties + return { + prop: subschema.to_dict() + for prop, subschema in self._properties.items() + } def _get_items(self, recurse=True): if not recurse: @@ -294,8 +294,5 @@ def _generate_array(self, array): self._add_items(array, 'add_object') def _generate_basic(self, val): - if val in JS_TYPES.keys(): - val_type = JS_TYPES[val] - else: - val_type = JS_TYPES[type(val)] + val_type = JS_TYPES[val] if val in JS_TYPES.keys() else JS_TYPES[type(val)] self._add_type(val_type)