Improve normalize_db_row by making it more strict on types.
This commit is contained in:
parent
8af64598a2
commit
46be4f8cff
1 changed files with 12 additions and 3 deletions
|
@ -4,11 +4,20 @@ from . import constants
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from . import ytrss
|
from . import ytrss
|
||||||
|
|
||||||
def normalize_db_row(db_row, table):
|
def normalize_db_row(db_row, table) -> dict:
|
||||||
if isinstance(db_row, (list, tuple)):
|
'''
|
||||||
db_row = dict(zip(constants.SQL_COLUMNS[table], db_row))
|
Raises KeyError if table is not one of the recognized tables.
|
||||||
|
|
||||||
|
Raises TypeError if db_row is not the right type.
|
||||||
|
'''
|
||||||
|
if isinstance(db_row, dict):
|
||||||
return db_row
|
return db_row
|
||||||
|
|
||||||
|
if isinstance(db_row, (list, tuple)):
|
||||||
|
return dict(zip(constants.SQL_COLUMNS[table], db_row))
|
||||||
|
|
||||||
|
raise TypeError(f'db_row should be {dict}, {list}, or {tuple}, not {type(db_row)}.')
|
||||||
|
|
||||||
class Base:
|
class Base:
|
||||||
def __init__(self, ycdldb):
|
def __init__(self, ycdldb):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
Loading…
Reference in a new issue