Skip to content

Commit f94678b

Browse files
Refactor libs/oracledb to meet mypy standard
1 parent 5e80f0a commit f94678b

File tree

7 files changed

+28
-31
lines changed

7 files changed

+28
-31
lines changed

libs/oracledb/langchain_oracledb/document_loaders/oracleadb_loader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def _run_query(self) -> List[Dict[str, Any]]:
9595
cursor.execute(self.query, self.parameter)
9696
else:
9797
cursor.execute(self.query)
98-
columns = [col[0] for col in cursor.description]
98+
99+
columns = (
100+
[col[0] for col in cursor.description] if cursor.description else []
101+
)
99102
data = cursor.fetchall()
100103
data = [
101104
{

libs/oracledb/langchain_oracledb/document_loaders/oracleai.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def read_file(
130130
with open(file_path, "rb") as f:
131131
data = f.read()
132132

133-
if data is None:
133+
if not data:
134134
return Document(page_content="", metadata=metadata)
135135

136136
mdata = cursor.var(oracledb.DB_TYPE_CLOB)
@@ -151,7 +151,7 @@ def read_file(
151151
)
152152
cursor.close()
153153

154-
if mdata is None:
154+
if mdata.getvalue() is None:
155155
metadata = {}
156156
else:
157157
doc_data = str(mdata.getvalue())
@@ -166,7 +166,7 @@ def read_file(
166166
metadata["_oid"] = doc_id
167167
metadata["_file"] = file_path
168168

169-
if text is None:
169+
if text.getvalue() is None:
170170
return Document(page_content="", metadata=metadata)
171171
else:
172172
return Document(page_content=str(text.getvalue()), metadata=metadata)

libs/oracledb/langchain_oracledb/embeddings/oracleai.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
102102
List of embeddings, one for each input text.
103103
"""
104104

105-
if texts is None:
106-
return None
107-
108105
embeddings: List[List[float]] = []
109106
try:
110107
# returns strings or bytes instead of a locator

libs/oracledb/langchain_oracledb/utilities/oracleai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_summary(self, docs: Any) -> List[str]:
9292
summ=summary,
9393
)
9494

95-
if summary is None:
95+
if summary.getvalue() is None:
9696
results.append("")
9797
else:
9898
results.append(str(summary.getvalue()))
@@ -114,7 +114,7 @@ def get_summary(self, docs: Any) -> List[str]:
114114
summ=summary,
115115
)
116116

117-
if summary is None:
117+
if summary.getvalue() is None:
118118
results.append("")
119119
else:
120120
results.append(str(summary.getvalue()))

libs/oracledb/langchain_oracledb/vectorstores/oraclevs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ async def _aembed_documents(self, texts: List[str]) -> List[List[float]]:
13301330
if isinstance(self.embedding_function, Embeddings):
13311331
return await self.embedding_function.aembed_documents(texts)
13321332
elif inspect.isawaitable(self.embedding_function):
1333-
return [await self.embedding_function(text) for text in texts]
1333+
return [await self.embedding_function(text) for text in texts] # type: ignore[unreachable]
13341334
elif callable(self.embedding_function):
13351335
return [self.embedding_function(text) for text in texts]
13361336
else:
@@ -1348,7 +1348,7 @@ async def _aembed_query(self, text: str) -> List[float]:
13481348
if isinstance(self.embedding_function, Embeddings):
13491349
return await self.embedding_function.aembed_query(text)
13501350
elif inspect.isawaitable(self.embedding_function):
1351-
return await self.embedding_function(text)
1351+
return await self.embedding_function(text) # type: ignore[unreachable]
13521352
else:
13531353
return self.embedding_function(text)
13541354

libs/oracledb/pyproject.toml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,17 @@ ignore = [
7272
docstring-code-format = true
7373

7474
[tool.mypy]
75-
ignore_missing_imports = "True"
76-
77-
# Disable specific error codes that are causing issues
78-
disallow_untyped_defs = "False"
79-
disable_error_code = ["attr-defined", "assignment", "var-annotated", "override", "union-attr", "arg-type"]
80-
81-
# TODO: LangChain Google settings
82-
# plugins = ["pydantic.mypy"]
83-
# strict = true
84-
# disallow_untyped_defs = true
85-
86-
# # TODO: activate for 'strict' checking
87-
# disallow_any_generics = false
88-
# warn_return_any = false
75+
plugins = ["pydantic.mypy"]
76+
check_untyped_defs = true
77+
error_summary = false
78+
pretty = true
79+
show_column_numbers = true
80+
show_error_codes = true
81+
show_error_context = true
82+
warn_redundant_casts = true
83+
warn_unreachable = true
84+
warn_unused_configs = true
85+
warn_unused_ignores = true
8986

9087
[tool.coverage.run]
9188
omit = ["tests/*"]

libs/oracledb/tests/integration_tests/vectorstores/test_oraclevs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ def test_db_filter_test() -> None:
19181918

19191919
exception_occurred = False
19201920
try:
1921-
db_filter_exc: dict = { # type: ignore[typeddict-unknown-key]
1921+
db_filter_exc: dict = {
19221922
"_xor": [ # Incorrect operation _xor
19231923
{"order": {"$lte": 4}},
19241924
{"id": "st"},
@@ -2055,7 +2055,7 @@ async def test_db_filter_test_async() -> None:
20552055

20562056
exception_occurred = False
20572057
try:
2058-
db_filter_exc: dict = { # type: ignore[typeddict-unknown-key]
2058+
db_filter_exc: dict = {
20592059
"_xor": [ # Incorrect operation _xor
20602060
{"order": {"$lte": 4}},
20612061
{"id": "st"},
@@ -2213,11 +2213,11 @@ def test_from_texts_lobs() -> None:
22132213
metadatas = [
22142214
{
22152215
"id": "cncpt_15.5.3.2.2_P4",
2216-
"link": "https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/logical-storage-structures.html#GUID-5387D7B2-C0CA-4C1E-811B-C7EB9B636442", # type: ignore[E501]
2216+
"link": "https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/logical-storage-structures.html#GUID-5387D7B2-C0CA-4C1E-811B-C7EB9B636442",
22172217
},
22182218
{
22192219
"id": "cncpt_15.5.5_P1",
2220-
"link": "https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/logical-storage-structures.html#GUID-D02B2220-E6F5-40D9-AFB5-BC69BCEF6CD4", # type: ignore[E501]
2220+
"link": "https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/logical-storage-structures.html#GUID-D02B2220-E6F5-40D9-AFB5-BC69BCEF6CD4",
22212221
},
22222222
]
22232223

@@ -2613,7 +2613,7 @@ def test_filters() -> None:
26132613
except Exception:
26142614
sys.exit(1)
26152615

2616-
def model1(_) -> list[float]: # type: ignore[no-untyped-def]
2616+
def model1(_) -> list[float]:
26172617
return [0.1, 0.2, 0.3]
26182618

26192619
# model1 = lambda x: [0.1, 0.2, 0.3]
@@ -2804,7 +2804,7 @@ async def test_filters_async() -> None:
28042804
except Exception:
28052805
sys.exit(1)
28062806

2807-
def model1(_) -> list[float]: # type: ignore[no-untyped-def]
2807+
def model1(_) -> list[float]:
28082808
return [0.1, 0.2, 0.3]
28092809

28102810
# model1 = lambda x: [0.1, 0.2, 0.3]

0 commit comments

Comments
 (0)