Skip to content

Commit

Permalink
remove none
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Dec 4, 2023
1 parent cbeeca3 commit 29ede4b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/repositories/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from app._typing import _UnsetSentinel
from app._typing import UNSET

from app.utils import remove_none_values

# +--------------+------------------------+------+-----+---------+-------+
# | Field | Type | Null | Key | Default | Extra |
# +--------------+------------------------+------+-----+---------+-------+
Expand Down Expand Up @@ -196,7 +198,7 @@ async def fetch_one(
"filename": filename,
}
map = await app.state.services.database.fetch_one(
" ".join(q for q in queries if q is not None), params
" ".join(q for q in queries if q is not None), remove_none_values(params)
)

return cast(Map, dict(map._mapping)) if map is not None else None
Expand Down
3 changes: 2 additions & 1 deletion app/repositories/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import app.state.services
from app._typing import _UnsetSentinel
from app._typing import UNSET
from app.utils import remove_none_values

# +-----------------+-----------------+------+-----+---------+----------------+
# | Field | Type | Null | Key | Default | Extra |
Expand Down Expand Up @@ -239,7 +240,7 @@ async def fetch_many(
}

recs = await app.state.services.database.fetch_all(
" ".join(q for q in queries if q is not None), params
" ".join(q for q in queries if q is not None), remove_none_values(params)
)
return cast(list[Score], [dict(r._mapping) for r in recs])

Expand Down
7 changes: 7 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,10 @@ def has_png_headers_and_trailers(data_view: memoryview) -> bool:
data_view[:8] == b"\x89PNG\r\n\x1a\n"
and data_view[-8:] == b"\x49END\xae\x42\x60\x82"
)


def remove_none_values(input_dict: dict[str, T | None]) -> dict[str, T]:
filtered_dict = {
key: value for key, value in input_dict.items() if value is not None
}
return filtered_dict

0 comments on commit 29ede4b

Please sign in to comment.