Skip to content

Commit

Permalink
refactor: Replace toolz.valmap in get_bindings_from_query_result
Browse files Browse the repository at this point in the history
Replace toolz.valmap in get_bindings_from_query_result with dict
comprehension and remove unnecessary type cast.

Since toolz.valmap was the only use of toolz in the codebase, the
toolz dependency can be removed.

Closes: #55
  • Loading branch information
lu-pl committed Aug 17, 2024
1 parent 0fa725b commit fb26dac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
13 changes: 1 addition & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
sparqlwrapper = "^2.0.0"
toolz = "^0.12.1"
pydantic = "^2.8.2"
fastapi = {extras = ["standard"], version = "^0.112.0"}
typeguard = "^4.3.0"
Expand Down
9 changes: 4 additions & 5 deletions rdfproxy/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""SPARQL/FastAPI utils."""

from collections.abc import Iterator, Mapping
from typing import Any, cast
from collections.abc import Iterator
from typing import Any

from SPARQLWrapper import QueryResult
from pydantic import BaseModel
from pydantic.fields import FieldInfo
from rdfproxy.utils._types import SPARQLBinding, _TModelInstance
from toolz import valmap


def get_bindings_from_query_result(query_result: QueryResult) -> Iterator[dict]:
Expand All @@ -18,9 +17,9 @@ def get_bindings_from_query_result(query_result: QueryResult) -> Iterator[dict]:
f"Received object with requestedFormat '{result_format}'."
)

query_json = cast(Mapping, query_result.convert())
query_json: dict = query_result.convert()
bindings = map(
lambda binding: valmap(lambda v: v["value"], binding),
lambda binding: {k: v["value"] for k, v in binding.items()},
query_json["results"]["bindings"],
)

Expand Down

0 comments on commit fb26dac

Please sign in to comment.