Skip to content

Commit

Permalink
chore(ruff): var name changes; unused import; formatting
Browse files Browse the repository at this point in the history
Handle vars variable hiding builting vars().

Use more descripting variable name.

Remove unused sys import.

Add double lines where needed.
  • Loading branch information
rouilj committed Jan 5, 2025
1 parent 8e0c7e1 commit db65d40
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions roundup/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
'''
__docformat__ = 'restructuredtext'

import sys

# These names are used to suppress import errors.
# If get_backend raises an ImportError with appropriate
# module name, have_backend quietly returns False.
Expand All @@ -31,18 +29,20 @@
'sqlite': ('sqlite3', '_sqlite3'),
}


def get_backend(name):
'''Get a specific backend by name.'''
vars = globals()
global_vars = globals()
# if requested backend has been imported yet, return current instance
if name in vars:
return vars[name]
if name in global_vars:
return global_vars[name]
# import the backend module
module_name = 'back_%s' % name
module = __import__(module_name, vars, level=1)
vars[name] = module
module = __import__(module_name, global_vars, level=1)
global_vars[name] = module
return module


def have_backend(name):
'''Is backend "name" available?'''
try:
Expand All @@ -62,6 +62,7 @@ def have_backend(name):
raise
return 0


def list_backends():
'''List all available backend names.
Expand All @@ -75,10 +76,10 @@ def list_backends():
because we do not need to monkey-patch list_backends.
'''
l = []
backend_list = []
for name in 'anydbm', 'mysql', 'sqlite', 'postgresql', 'memorydb':
if have_backend(name):
l.append(name)
return l
backend_list.append(name)
return backend_list

# vim: set filetype=python sts=4 sw=4 et si :

0 comments on commit db65d40

Please sign in to comment.