From 9c0f72c624a49efe903d7294c66fb7a64974415c Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 28 Feb 2023 01:28:58 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- cli/cli.py | 19 ++++++++++++------- cli/commands/cmd_api.py | 2 +- cli/commands/cmd_db.py | 2 +- cli/commands/cmd_routes.py | 2 +- config/settings.py | 4 +++- facilities/databases/DBMixins.py | 4 +--- facilities/mimes.py | 6 +----- models/User.py | 5 ++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cli/cli.py b/cli/cli.py index 47e5d2d..caf6ffa 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -25,17 +25,17 @@ def vlog(self, msg, *args): pass_context = click.make_pass_decorator(Context, ensure = True) -cmd_folder = os.path.join(BASE_DIR + '/cli', 'commands') +cmd_folder = os.path.join(f'{BASE_DIR}/cli', 'commands') class CLI(click.MultiCommand): def list_commands(self, ctx): - rv = [] - for filename in os.listdir(cmd_folder): - if filename.endswith('.py') and \ - filename.startswith('cmd_'): - rv.append(filename[4:-3]) + rv = [ + filename[4:-3] + for filename in os.listdir(cmd_folder) + if filename.endswith('.py') and filename.startswith('cmd_') + ] rv.sort() return rv @@ -43,7 +43,12 @@ def get_command(self, ctx, name): try: if sys.version_info[0] == 2: name = name.encode('ascii', 'replace') - mod = __import__('cli.commands.cmd_' + name, locals = None, globals = None, fromlist = ['cli']) + mod = __import__( + f'cli.commands.cmd_{name}', + locals=None, + globals=None, + fromlist=['cli'], + ) except ImportError: return return mod.cli diff --git a/cli/commands/cmd_api.py b/cli/commands/cmd_api.py index a344da6..c10b8bd 100644 --- a/cli/commands/cmd_api.py +++ b/cli/commands/cmd_api.py @@ -38,7 +38,7 @@ def make_api(api_name: str, model): f"class {api_name.capitalize()}View(Resource):\n" f" pass") - with open(f'api/__init__.py', 'a+') as f: + with open('api/__init__.py', 'a+') as f: f.write( f'from api.{api_name.capitalize()} import {api_name.capitalize()}View\n') f.write( diff --git a/cli/commands/cmd_db.py b/cli/commands/cmd_db.py index b7c6c9b..c58a889 100644 --- a/cli/commands/cmd_db.py +++ b/cli/commands/cmd_db.py @@ -144,7 +144,7 @@ class {model_name.capitalize()}(Model): pass ''') - with open(f'models/__init__.py', 'a+') as f: + with open('models/__init__.py', 'a+') as f: f.write( f'from models.{model_name.capitalize()} import {model_name.capitalize()}\n') diff --git a/cli/commands/cmd_routes.py b/cli/commands/cmd_routes.py index a37eeb7..7a4d7db 100644 --- a/cli/commands/cmd_routes.py +++ b/cli/commands/cmd_routes.py @@ -25,7 +25,7 @@ def list_(): output[rule.endpoint] = route - endpoint_padding = max(len(endpoint) for endpoint in output.keys()) + 2 + endpoint_padding = max(len(endpoint) for endpoint in output) + 2 for key in sorted(output): if 'debugtoolbar' not in key and 'debug_toolbar' not in key: diff --git a/config/settings.py b/config/settings.py index 642425f..7c78d4b 100644 --- a/config/settings.py +++ b/config/settings.py @@ -61,7 +61,9 @@ formatter = logging.Formatter( "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") -handler = RotatingFileHandler(LOG_DIR + '/app.log', maxBytes = 1000000, backupCount = 5) +handler = RotatingFileHandler( + f'{LOG_DIR}/app.log', maxBytes=1000000, backupCount=5 +) handler.setLevel(logging.DEBUG) handler.setFormatter(formatter) app.logger.addHandler(handler) diff --git a/facilities/databases/DBMixins.py b/facilities/databases/DBMixins.py index 89d95c7..3ba5b83 100644 --- a/facilities/databases/DBMixins.py +++ b/facilities/databases/DBMixins.py @@ -105,9 +105,7 @@ def __ne__(self, other): Checks the inequality of two `UserMixin` objects using `get_id`. """ equal = self.__eq__(other) - if equal is NotImplemented: - return NotImplemented - return not equal + return NotImplemented if equal is NotImplemented else not equal class AnonymousUserMixin: diff --git a/facilities/mimes.py b/facilities/mimes.py index 9aaa33f..3b71621 100755 --- a/facilities/mimes.py +++ b/facilities/mimes.py @@ -105,8 +105,4 @@ def get_mimes(extension=None): def get_extensions(mime_type=None): """Returns possible extensions for the given mime_type""" - exts = [] - for ext in _mime_types: - if mime_type in _mime_types[ext]: - exts.append(ext) - return exts + return [ext for ext in _mime_types if mime_type in _mime_types[ext]] diff --git a/models/User.py b/models/User.py index 35eca15..10c9651 100644 --- a/models/User.py +++ b/models/User.py @@ -45,7 +45,7 @@ class User(Model): # __guarded__ = ['id', 'password', 'password_again'] def __repr__(self): - return ''.format(self.username) + return f'' @property def rolenames(self): @@ -56,8 +56,7 @@ def rolenames(self): @classmethod def lookup(cls, username): - result = cls.query().where('username', username).first_or_fail() - if result: + if result := cls.query().where('username', username).first_or_fail(): return result else: return None