Skip to content

Commit 8d43ad4

Browse files
authored
INTPYTHON-816 - Bump minimum Python version to 3.10 (#241)
[INTPYTHON-816](https://jira.mongodb.org/browse/INTPYTHON-816) ## Summary LangChain 1.0 requires Python 3.10+. Updating our own minimum version now before the package split will reduce the complexity of doing so. ## Changes in this PR Bump minimum Python version across the board to 3.10. Update ruff to the latest release for fixes such as the removal of [UP038](https://docs.astral.sh/ruff/rules/non-pep604-isinstance/).
1 parent 6b7d433 commit 8d43ad4

File tree

36 files changed

+140
-1380
lines changed

36 files changed

+140
-1380
lines changed

.github/workflows/_lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# Starting new jobs is also relatively slow,
3030
# so linting on fewer versions makes CI faster.
3131
python-version:
32-
- "3.9"
32+
- "3.10"
3333
- "3.13"
3434
steps:
3535
- uses: actions/checkout@v5

.github/workflows/_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
python-version:
21-
- "3.9"
21+
- "3.10"
2222
- "3.13"
2323
name: "run test #${{ matrix.python-version }}"
2424
steps:

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
uses: astral-sh/setup-uv@2ddd2b9cb38ad8efd50337e8ab201519a34c9f24 # v7
8787
with:
8888
enable-cache: true
89-
python-version: 3.9
89+
python-version: "3.10"
9090
- run: just docs
9191

9292
ci_success:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040

4141
- repo: https://github.com/astral-sh/ruff-pre-commit
4242
# Ruff version.
43-
rev: v0.8.5
43+
rev: v0.14.2
4444
hooks:
4545
# Run the linter.
4646
- id: ruff

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,8 @@ just codespell
135135
```
136136

137137
If codespell is incorrectly flagging a word, you can skip spellcheck for that word by adding it to the codespell config in the `.pre-commit-config.yaml` file.
138+
139+
### CI Configuration
140+
The CI configuration for this project is located in the `.github/workflows` directory.
141+
The `.github/scripts/check_diff.py` script is run automatically at the start of CI to determine which parts of the codebase have changed and need to be tested. I
142+
f you add new packages or change the directory structure, update this script accordingly.

docs/_extensions/gallery_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def run(self) -> List[nodes.Node]:
108108

109109
# Parse the template with Sphinx Design to create an output container
110110
# Prep the options for the template grid
111-
class_ = "gallery-directive" + f' {self.options.get("class-container", "")}'
111+
class_ = "gallery-directive" + f" {self.options.get('class-container', '')}"
112112
options = {"gutter": 2, "class-container": class_}
113113
options_str = "\n".join(f":{k}: {v}" for k, v in options.items())
114114

docs/create_api_rst.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _construct_doc(
269269
.. _{package_namespace}:
270270
271271
======================================
272-
{package_namespace.replace('_', '-').replace('.', '-')}: {package_version}
272+
{package_namespace.replace("_", "-").replace(".", "-")}: {package_version}
273273
======================================
274274
275275
.. automodule:: {package_namespace}
@@ -327,7 +327,7 @@ def _construct_doc(
327327

328328
index_autosummary += f"""
329329
:ref:`{package_namespace}_{module}`
330-
{'^' * (len(package_namespace) + len(module) + 8)}
330+
{"^" * (len(package_namespace) + len(module) + 8)}
331331
"""
332332

333333
if classes:
@@ -366,7 +366,7 @@ def _construct_doc(
366366
367367
"""
368368
index_autosummary += f"""
369-
{class_['qualified_name']}
369+
{class_["qualified_name"]}
370370
"""
371371

372372
if functions:
@@ -429,7 +429,7 @@ def _construct_doc(
429429
430430
"""
431431
index_autosummary += f"""
432-
{class_['qualified_name']}
432+
{class_["qualified_name"]}
433433
"""
434434

435435
if deprecated_functions:

libs/langchain-mongodb/langchain_mongodb/docstores.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ def mset(
9999
batch_size: Number of documents to insert at a time.
100100
Tuning this may help with performance and sidestep MongoDB limits.
101101
"""
102-
keys, docs = zip(*key_value_pairs)
102+
keys, docs = zip(*key_value_pairs, strict=True)
103103
n_docs = len(docs)
104104
start = 0
105105
for end in range(batch_size, n_docs + batch_size, batch_size):
106106
texts, metadatas = zip(
107-
*[(doc.page_content, doc.metadata) for doc in docs[start:end]]
107+
*[(doc.page_content, doc.metadata) for doc in docs[start:end]],
108+
strict=True,
108109
)
109110
self.insert_many(texts=texts, metadatas=metadatas, ids=keys[start:end]) # type: ignore
110111
start = end
@@ -149,6 +150,7 @@ def insert_many(
149150
in the batch that do not have conflicting _ids will still be inserted.
150151
"""
151152
to_insert = [
152-
{"_id": i, self._text_key: t, **m} for i, t, m in zip(ids, texts, metadatas)
153+
{"_id": i, self._text_key: t, **m}
154+
for i, t, m in zip(ids, texts, metadatas, strict=True)
153155
]
154156
self.collection.insert_many(to_insert) # type: ignore

libs/langchain-mongodb/langchain_mongodb/indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update(
8585
if len(keys) != len(group_ids):
8686
raise ValueError("Number of keys does not match number of group_ids")
8787

88-
for key, group_id in zip(keys, group_ids):
88+
for key, group_id in zip(keys, group_ids, strict=True):
8989
self._collection.find_one_and_update(
9090
{"namespace": self.namespace, "key": key},
9191
{"$set": {"group_id": group_id, "updated_at": self.get_time()}},

libs/langchain-mongodb/langchain_mongodb/vectorstores.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def add_texts(
356356
metadatas_batch = []
357357
size = 0
358358
i = 0
359-
for j, (text, metadata) in enumerate(zip(texts, _metadatas)):
359+
for j, (text, metadata) in enumerate(zip(texts, _metadatas, strict=True)):
360360
size += len(text) + len(metadata)
361361
texts_batch.append(text)
362362
metadatas_batch.append(metadata)
@@ -442,7 +442,9 @@ def bulk_embed_and_insert_texts(
442442
self._embedding_key: embedding,
443443
**m,
444444
}
445-
for i, t, m, embedding in zip(ids, texts, metadatas, embeddings)
445+
for i, t, m, embedding in zip(
446+
ids, texts, metadatas, embeddings, strict=True
447+
)
446448
]
447449
operations = [ReplaceOne({"_id": doc["_id"]}, doc, upsert=True) for doc in docs]
448450
# insert the documents in MongoDB Atlas
@@ -478,7 +480,8 @@ def add_documents(
478480
start = 0
479481
for end in range(batch_size, n_docs + batch_size, batch_size):
480482
texts, metadatas = zip(
481-
*[(doc.page_content, doc.metadata) for doc in documents[start:end]]
483+
*[(doc.page_content, doc.metadata) for doc in documents[start:end]],
484+
strict=True,
482485
)
483486
result_ids.extend(
484487
self.bulk_embed_and_insert_texts(

0 commit comments

Comments
 (0)