From 0cc1062c52476e0bd2675209a4e3548fc6818f41 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 25 Oct 2019 08:06:26 -0300 Subject: [PATCH] flake8 pass - fix test_empty_embed not actually reporting on empty embeds --- litecord/blueprints/auth.py | 2 +- litecord/blueprints/users.py | 2 +- litecord/enums.py | 2 +- litecord/pubsub/dispatcher.py | 11 +++++++---- litecord/utils.py | 4 ++-- manage/cmd/migration/command.py | 2 +- tests/test_embeds.py | 10 +++------- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/litecord/blueprints/auth.py b/litecord/blueprints/auth.py index 38ce17c..01a5454 100644 --- a/litecord/blueprints/auth.py +++ b/litecord/blueprints/auth.py @@ -64,7 +64,7 @@ async def register(): j = await request.get_json() - if not "password" in j: + if "password" not in j: # we need a password to generate a token. # passwords are optional, so j["password"] = "default_password" diff --git a/litecord/blueprints/users.py b/litecord/blueprints/users.py index d5bda02..f9b8466 100644 --- a/litecord/blueprints/users.py +++ b/litecord/blueprints/users.py @@ -259,7 +259,7 @@ async def patch_me(): user_id, ) - if user["email"] is None and not "new_password" in j: + if user["email"] is None and "new_password" not in j: raise BadRequest("missing password", {"password": "Please set a password."}) if "new_password" in j and j["new_password"]: diff --git a/litecord/enums.py b/litecord/enums.py index aaf71a0..ce68e18 100644 --- a/litecord/enums.py +++ b/litecord/enums.py @@ -33,7 +33,7 @@ class EasyEnum(Enum): class Flags: """Construct a class that represents a bitfield. - + You can use it like this: >>> class MyField(Flags): field_1 = 1 diff --git a/litecord/pubsub/dispatcher.py b/litecord/pubsub/dispatcher.py index 7c4246f..747ad63 100644 --- a/litecord/pubsub/dispatcher.py +++ b/litecord/pubsub/dispatcher.py @@ -25,17 +25,20 @@ from logbook import Logger log = Logger(__name__) +def _identity(_self, x): + return x + + class Dispatcher: """Pub/Sub backend dispatcher. - + This just declares functions all Dispatcher subclasses can implement. This does not mean all Dispatcher subclasses have them implemented. """ - # the _ parameter is for (self) - KEY_TYPE = lambda _, x: x - VAL_TYPE = lambda _, x: x + KEY_TYPE = _identity + VAL_TYPE = _identity def __init__(self, main): #: main EventDispatcher diff --git a/litecord/utils.py b/litecord/utils.py index b2c5478..a0f5587 100644 --- a/litecord/utils.py +++ b/litecord/utils.py @@ -45,7 +45,7 @@ async def task_wrapper(name: str, coro): await coro except asyncio.CancelledError: pass - except: + except Exception: log.exception("{} task error", name) @@ -201,7 +201,7 @@ def to_update(j: dict, orig: dict, field: str) -> bool: async def search_result_from_list(rows: List) -> Dict[str, Any]: """Generate the end result of the search query, given a list of rows. - + Each row must contain: - A bigint on `current_id` - An int (?) on `total_results` diff --git a/manage/cmd/migration/command.py b/manage/cmd/migration/command.py index 003d675..605ee61 100644 --- a/manage/cmd/migration/command.py +++ b/manage/cmd/migration/command.py @@ -170,7 +170,7 @@ async def apply_migration(app, migration: Migration) -> bool: log.info("applied {} {}", migration.id, migration.name) return True - except: + except Exception: log.exception("failed to run migration, rollbacking log") await _delete_log(app, migration.id) diff --git a/tests/test_embeds.py b/tests/test_embeds.py index 5720243..05ea0b8 100644 --- a/tests/test_embeds.py +++ b/tests/test_embeds.py @@ -30,20 +30,16 @@ def valid(embed: dict): try: validate_embed(embed) return True - except: + except Exception: return False def invalid(embed): - try: - validate_embed(embed) - return False - except: - return True + return not valid(embed) def test_empty_embed(): - valid({}) + assert valid({}) def test_basic_embed():