Skip to content

Commit fd276af

Browse files
authored
Removes unneeded # type: ignore comments (#198)
* Fixes mypy issue for execute_query function * Updated type ignore comments in langchain_compatiblity.py
1 parent fd9cd18 commit fd276af

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

examples/customize/answer/langchain_compatiblity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
driver,
3131
index_name=INDEX,
3232
retrieval_query="WITH node, score RETURN node.title as title, node.plot as plot",
33-
embedder=embedder, # type: ignore
33+
embedder=embedder, # type: ignore[arg-type, unused-ignore]
3434
)
3535

3636
llm = ChatOpenAI(model="gpt-4o", temperature=0)
3737

3838
rag = GraphRAG(
3939
retriever=retriever,
40-
llm=llm, # type: ignore
40+
llm=llm, # type: ignore[arg-type, unused-ignore]
4141
)
4242

4343
result = rag.search("Tell me more about Avatar movies")

src/neo4j_graphrag/experimental/components/resolver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EntityResolver(Component, abc.ABC):
2626
"""Entity resolution base class
2727
2828
Args:
29-
driver (neo4j.driver): The Neo4j driver to connect to the database.
29+
driver (neo4j.Driver): The Neo4j driver to connect to the database.
3030
filter_query (Optional[str]): Cypher query to select the entities to resolve. By default, all nodes with __Entity__ label are used
3131
"""
3232

@@ -47,7 +47,7 @@ class SinglePropertyExactMatchResolver(EntityResolver):
4747
"""Resolve entities with same label and exact same property (default is "name").
4848
4949
Args:
50-
driver (neo4j.driver): The Neo4j driver to connect to the database.
50+
driver (neo4j.Driver): The Neo4j driver to connect to the database.
5151
filter_query (Optional[str]): To reduce the resolution scope, add a Cypher WHERE clause.
5252
resolve_property (str): The property that will be compared (default: "name"). If values match exactly, entities are merged.
5353
neo4j_database (Optional[str]): The name of the Neo4j database to write to. Defaults to 'neo4j' if not provided.
@@ -94,7 +94,7 @@ async def run(self) -> ResolutionStats:
9494
if self.filter_query:
9595
match_query += self.filter_query
9696
stat_query = f"{match_query} RETURN count(entity) as c"
97-
records = await execute_query(
97+
records, _, _ = await execute_query(
9898
self.driver,
9999
stat_query,
100100
database_=self.database,
@@ -130,7 +130,7 @@ async def run(self) -> ResolutionStats:
130130
"YIELD node "
131131
"RETURN count(node) as c "
132132
)
133-
records = await execute_query(
133+
records, _, _ = await execute_query(
134134
self.driver,
135135
merge_nodes_query,
136136
database_=self.database,

src/neo4j_graphrag/retrievers/text2cypher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Text2CypherRetriever(Retriever):
5151
then retrieves records from a Neo4j database using the generated Cypher query
5252
5353
Args:
54-
driver (neo4j.driver): The Neo4j Python driver.
54+
driver (neo4j.Driver): The Neo4j Python driver.
5555
llm (neo4j_graphrag.generation.llm.LLMInterface): LLM object to generate the Cypher query.
5656
neo4j_schema (Optional[str]): Neo4j schema used to generate the Cypher query.
5757
examples (Optional[list[str], optional): Optional user input/query pairs for the LLM to use as examples.

src/neo4j_graphrag/utils.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# limitations under the License.
1515
from __future__ import annotations
1616

17-
import inspect
18-
from typing import Any, Optional, Union
17+
from typing import Any, Optional
1918

2019
import neo4j
2120

@@ -28,12 +27,10 @@ def validate_search_query_input(
2827

2928

3029
async def execute_query(
31-
driver: Union[neo4j.Driver, neo4j.AsyncDriver], query: str, **kwargs: Any
32-
) -> list[neo4j.Record]:
33-
if inspect.iscoroutinefunction(driver.execute_query):
34-
records, _, _ = await driver.execute_query(query, **kwargs)
35-
return records # type: ignore[no-any-return]
36-
# ignoring type because mypy complains about coroutine
37-
# but we're sure at this stage we do not have a coroutine anymore
38-
records, _, _ = driver.execute_query(query, **kwargs) # type: ignore[misc]
39-
return records # type: ignore[no-any-return]
30+
driver: neo4j.Driver | neo4j.AsyncDriver, query: str, **kwargs: Any
31+
) -> Any:
32+
if isinstance(driver, neo4j.AsyncDriver):
33+
result = await driver.execute_query(query, **kwargs)
34+
else:
35+
result = driver.execute_query(query, **kwargs)
36+
return result

0 commit comments

Comments
 (0)