Skip to content

Commit

Permalink
Change default argument from empty dict to None
Browse files Browse the repository at this point in the history
  • Loading branch information
leila-messallem committed May 21, 2024
1 parent 2eaacad commit bbfb30c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/neo4j_genai/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any
from typing import Any, Optional

import neo4j

Expand Down Expand Up @@ -50,20 +50,22 @@
"""


def _query_database(
driver: neo4j.Driver, query: str, params: dict = {}
def query_database(
driver: neo4j.Driver, query: str, params: Optional[dict] = None
) -> list[dict[str, Any]]:
"""
Queries the database.
Args:
driver (neo4j.Driver): Neo4j Python driver instance.
query (str): The cypher query.
params (dict, optional): The query parameters. Defaults to {}.
params (dict, optional): The query parameters. Defaults to None.
Returns:
List[Dict[str, Any]]: the result of the query in json format.
"""
if params is None:
params = {}
data = driver.execute_query(query, params)
return [r.data() for r in data.records]

Expand All @@ -82,7 +84,7 @@ def get_schema(
"""
node_properties = [
data["output"]
for data in _query_database(
for data in query_database(
driver,
NODE_PROPERTIES_QUERY,
params={"EXCLUDED_LABELS": EXCLUDED_LABELS + [BASE_ENTITY_LABEL]},
Expand All @@ -91,13 +93,13 @@ def get_schema(

rel_properties = [
data["output"]
for data in _query_database(
for data in query_database(
driver, REL_PROPERTIES_QUERY, params={"EXCLUDED_LABELS": EXCLUDED_RELS}
)
]
relationships = [
data["output"]
for data in _query_database(
for data in query_database(
driver,
REL_QUERY,
params={"EXCLUDED_LABELS": EXCLUDED_LABELS + [BASE_ENTITY_LABEL]},
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_get_schema_happy_path(driver):
)


@patch("neo4j_genai.schema._query_database", side_effect=_query_return_value)
@patch("neo4j_genai.schema.query_database", side_effect=_query_return_value)
def test_get_schema_ensure_formatted_response(driver):
result = get_schema(driver)
assert (
Expand Down

0 comments on commit bbfb30c

Please sign in to comment.