Skip to content

Commit e731ba1

Browse files
authored
style: more refs work (#33616)
1 parent 557fc9a commit e731ba1

File tree

16 files changed

+193
-206
lines changed

16 files changed

+193
-206
lines changed

libs/core/langchain_core/documents/transformers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def transform_documents(
5757
"""Transform a list of documents.
5858
5959
Args:
60-
documents: A sequence of Documents to be transformed.
60+
documents: A sequence of `Document` objects to be transformed.
6161
6262
Returns:
63-
A sequence of transformed Documents.
63+
A sequence of transformed `Document` objects.
6464
"""
6565

6666
async def atransform_documents(
@@ -69,10 +69,10 @@ async def atransform_documents(
6969
"""Asynchronously transform a list of documents.
7070
7171
Args:
72-
documents: A sequence of Documents to be transformed.
72+
documents: A sequence of `Document` objects to be transformed.
7373
7474
Returns:
75-
A sequence of transformed Documents.
75+
A sequence of transformed `Document` objects.
7676
"""
7777
return await run_in_executor(
7878
None, self.transform_documents, documents, **kwargs

libs/core/langchain_core/load/dump.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _dump_pydantic_models(obj: Any) -> Any:
3838

3939

4040
def dumps(obj: Any, *, pretty: bool = False, **kwargs: Any) -> str:
41-
"""Return a json string representation of an object.
41+
"""Return a JSON string representation of an object.
4242
4343
Args:
4444
obj: The object to dump.
@@ -47,7 +47,7 @@ def dumps(obj: Any, *, pretty: bool = False, **kwargs: Any) -> str:
4747
**kwargs: Additional arguments to pass to `json.dumps`
4848
4949
Returns:
50-
A json string representation of the object.
50+
A JSON string representation of the object.
5151
5252
Raises:
5353
ValueError: If `default` is passed as a kwarg.
@@ -71,14 +71,12 @@ def dumps(obj: Any, *, pretty: bool = False, **kwargs: Any) -> str:
7171
def dumpd(obj: Any) -> Any:
7272
"""Return a dict representation of an object.
7373
74-
!!! note
75-
Unfortunately this function is not as efficient as it could be because it first
76-
dumps the object to a json string and then loads it back into a dictionary.
77-
7874
Args:
7975
obj: The object to dump.
8076
8177
Returns:
82-
dictionary that can be serialized to json using json.dumps
78+
Dictionary that can be serialized to json using `json.dumps`.
8379
"""
80+
# Unfortunately this function is not as efficient as it could be because it first
81+
# dumps the object to a json string and then loads it back into a dictionary.
8482
return json.loads(dumps(obj))

libs/core/langchain_core/messages/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ def filter_messages(
439439
exclude_ids: Message IDs to exclude.
440440
exclude_tool_calls: Tool call IDs to exclude.
441441
Can be one of the following:
442-
- `True`: all `AIMessage`s with tool calls and all
443-
`ToolMessage` objects will be excluded.
442+
- `True`: All `AIMessage` objects with tool calls and all `ToolMessage`
443+
objects will be excluded.
444444
- a sequence of tool call IDs to exclude:
445445
- `ToolMessage` objects with the corresponding tool call ID will be
446446
excluded.

libs/core/langchain_core/runnables/branch.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
class RunnableBranch(RunnableSerializable[Input, Output]):
4141
"""Runnable that selects which branch to run based on a condition.
4242
43-
The Runnable is initialized with a list of (condition, Runnable) pairs and
43+
The Runnable is initialized with a list of `(condition, Runnable)` pairs and
4444
a default branch.
4545
4646
When operating on an input, the first condition that evaluates to True is
47-
selected, and the corresponding Runnable is run on the input.
47+
selected, and the corresponding `Runnable` is run on the input.
4848
49-
If no condition evaluates to True, the default branch is run on the input.
49+
If no condition evaluates to `True`, the default branch is run on the input.
5050
5151
Examples:
5252
```python
@@ -65,9 +65,9 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
6565
"""
6666

6767
branches: Sequence[tuple[Runnable[Input, bool], Runnable[Input, Output]]]
68-
"""A list of (condition, Runnable) pairs."""
68+
"""A list of `(condition, Runnable)` pairs."""
6969
default: Runnable[Input, Output]
70-
"""A Runnable to run if no condition is met."""
70+
"""A `Runnable` to run if no condition is met."""
7171

7272
def __init__(
7373
self,
@@ -79,15 +79,15 @@ def __init__(
7979
]
8080
| RunnableLike,
8181
) -> None:
82-
"""A Runnable that runs one of two branches based on a condition.
82+
"""A `Runnable` that runs one of two branches based on a condition.
8383
8484
Args:
85-
*branches: A list of (condition, Runnable) pairs.
86-
Defaults a Runnable to run if no condition is met.
85+
*branches: A list of `(condition, Runnable)` pairs.
86+
Defaults a `Runnable` to run if no condition is met.
8787
8888
Raises:
8989
ValueError: If the number of branches is less than 2.
90-
TypeError: If the default branch is not Runnable, Callable or Mapping.
90+
TypeError: If the default branch is not `Runnable`, `Callable` or `Mapping`.
9191
TypeError: If a branch is not a tuple or list.
9292
ValueError: If a branch is not of length 2.
9393
"""

libs/core/langchain_core/vectorstores/in_memory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def get_by_ids(self, ids: Sequence[str], /) -> list[Document]:
260260
ids: The ids of the documents to get.
261261
262262
Returns:
263-
A list of Document objects.
263+
A list of `Document` objects.
264264
"""
265265
documents = []
266266

@@ -284,7 +284,7 @@ async def aget_by_ids(self, ids: Sequence[str], /) -> list[Document]:
284284
ids: The ids of the documents to get.
285285
286286
Returns:
287-
A list of Document objects.
287+
A list of `Document` objects.
288288
"""
289289
return self.get_by_ids(ids)
290290

libs/partners/mistralai/langchain_mistralai/chat_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def _convert_message_to_mistral_chat_message(
446446

447447

448448
class ChatMistralAI(BaseChatModel):
449-
"""A chat model that uses the MistralAI API."""
449+
"""A chat model that uses the Mistral AI API."""
450450

451451
# The type for client and async_client is ignored because the type is not
452452
# an Optional after the model is initialized and the model_validator
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""Base Test classes for standard testing.
1+
"""Base test classes for standard testing.
22
3-
To learn how to use these classes, see the
4-
[integration standard testing](https://python.langchain.com/docs/contributing/how_to/integrations/standard_tests/)
5-
guide.
3+
To learn how to use these, see the guide on
4+
[integrating standard tests](https://docs.langchain.com/oss/python/contributing/standard-tests-langchain).
65
"""

libs/standard-tests/langchain_tests/integration_tests/chat_models.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,21 @@ def chat_model_params(self) -> dict:
182182
183183
Test subclasses **must** implement the following two properties:
184184
185-
chat_model_class
186-
The chat model class to test, e.g., `ChatParrotLink`.
185+
`chat_model_class`: The chat model class to test, e.g., `ChatParrotLink`.
187186
188-
```python
189-
@property
190-
def chat_model_class(self) -> Type[ChatParrotLink]:
191-
return ChatParrotLink
192-
```
187+
```python
188+
@property
189+
def chat_model_class(self) -> Type[ChatParrotLink]:
190+
return ChatParrotLink
191+
```
193192
194-
chat_model_params
195-
Initialization parameters for the chat model.
193+
`chat_model_params`: Initialization parameters for the chat model.
196194
197-
```python
198-
@property
199-
def chat_model_params(self) -> dict:
200-
return {"model": "bird-brain-001", "temperature": 0}
201-
```
195+
```python
196+
@property
197+
def chat_model_params(self) -> dict:
198+
return {"model": "bird-brain-001", "temperature": 0}
199+
```
202200
203201
In addition, test subclasses can control what features are tested (such as tool
204202
calling or multi-modality) by selectively overriding the following properties.
@@ -266,7 +264,7 @@ def has_tool_choice(self) -> bool:
266264
`with_structured_output` method is overridden. If the base implementation is
267265
intended to be used, this method should be overridden.
268266
269-
See: https://python.langchain.com/docs/concepts/structured_outputs/
267+
See: https://docs.langchain.com/oss/python/langchain/structured-output
270268
271269
```python
272270
@property
@@ -290,7 +288,7 @@ def structured_output_kwargs(self) -> dict:
290288
Boolean property indicating whether the chat model supports JSON mode in
291289
`with_structured_output`.
292290
293-
See: https://python.langchain.com/docs/concepts/structured_outputs/#json-mode
291+
See: https://docs.langchain.com/oss/python/langchain/structured-output
294292
295293
```python
296294
@property
@@ -324,7 +322,7 @@ def supports_json_mode(self) -> bool:
324322
}
325323
```
326324
327-
See https://python.langchain.com/docs/concepts/multimodality/
325+
See https://docs.langchain.com/oss/python/langchain/models#multimodal
328326
329327
```python
330328
@property
@@ -349,7 +347,7 @@ def supports_image_inputs(self) -> bool:
349347
}
350348
```
351349
352-
See https://python.langchain.com/docs/concepts/multimodality/
350+
See https://docs.langchain.com/oss/python/langchain/models#multimodal
353351
354352
```python
355353
@property
@@ -374,7 +372,7 @@ def supports_image_urls(self) -> bool:
374372
}
375373
```
376374
377-
See https://python.langchain.com/docs/concepts/multimodality/
375+
See https://docs.langchain.com/oss/python/langchain/models#multimodal
378376
379377
```python
380378
@property
@@ -399,7 +397,7 @@ def supports_pdf_inputs(self) -> bool:
399397
}
400398
```
401399
402-
See https://python.langchain.com/docs/concepts/multimodality/
400+
See https://docs.langchain.com/oss/python/langchain/models#multimodal
403401
404402
```python
405403
@property
@@ -420,8 +418,8 @@ def supports_audio_inputs(self) -> bool:
420418
421419
Defaults to `True`.
422420
423-
`usage_metadata` is an optional dict attribute on `AIMessage`s that track input
424-
and output tokens.
421+
`usage_metadata` is an optional dict attribute on `AIMessage` objects that track
422+
input and output tokens.
425423
[See more](https://python.langchain.com/api_reference/core/messages/langchain_core.messages.ai.UsageMetadata.html).
426424
427425
```python
@@ -537,8 +535,8 @@ def supports_pdf_tool_message(self) -> bool:
537535
Property controlling what usage metadata details are emitted in both invoke
538536
and stream.
539537
540-
`usage_metadata` is an optional dict attribute on `AIMessage`s that track input
541-
and output tokens.
538+
`usage_metadata` is an optional dict attribute on `AIMessage` objects that track
539+
input and output tokens.
542540
[See more](https://python.langchain.com/api_reference/core/messages/langchain_core.messages.ai.UsageMetadata.html).
543541
544542
It includes optional keys `input_token_details` and `output_token_details`
@@ -580,9 +578,7 @@ def enable_vcr_tests(self) -> bool:
580578
also exclude additional headers, override the default exclusions, or apply
581579
other customizations to the VCR configuration. See example below:
582580
583-
```python
584-
:caption: tests/conftest.py
585-
581+
```python title="tests/conftest.py"
586582
import pytest
587583
from langchain_tests.conftest import (
588584
_base_vcr_config as _base_vcr_config,
@@ -617,9 +613,7 @@ def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
617613
to your VCR fixture and enable this serializer in the config. See
618614
example below:
619615
620-
```python
621-
:caption: tests/conftest.py
622-
616+
```python title="tests/conftest.py"
623617
import pytest
624618
from langchain_tests.conftest import (
625619
CustomPersister,
@@ -658,7 +652,6 @@ def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
658652
def pytest_recording_configure(config: dict, vcr: VCR) -> None:
659653
vcr.register_persister(CustomPersister())
660654
vcr.register_serializer("yaml.gz", CustomSerializer())
661-
662655
```
663656
664657
You can inspect the contents of the compressed cassettes (e.g., to

libs/standard-tests/langchain_tests/integration_tests/tools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class ToolsIntegrationTests(ToolsTests):
1212
def test_invoke_matches_output_schema(self, tool: BaseTool) -> None:
1313
"""Test invoke matches output schema.
1414
15-
If invoked with a ToolCall, the tool should return a valid ToolMessage content.
15+
If invoked with a `ToolCall`, the tool should return a valid `ToolMessage`
16+
content.
1617
1718
If you have followed the [custom tool guide](https://python.langchain.com/docs/how_to/custom_tools/),
1819
this test should always pass because ToolCall inputs are handled by the
@@ -44,7 +45,8 @@ def test_invoke_matches_output_schema(self, tool: BaseTool) -> None:
4445
async def test_async_invoke_matches_output_schema(self, tool: BaseTool) -> None:
4546
"""Test async invoke matches output schema.
4647
47-
If ainvoked with a ToolCall, the tool should return a valid ToolMessage content.
48+
If ainvoked with a `ToolCall`, the tool should return a valid `ToolMessage`
49+
content.
4850
4951
For debugging tips, see `test_invoke_matches_output_schema`.
5052
"""
@@ -68,9 +70,9 @@ async def test_async_invoke_matches_output_schema(self, tool: BaseTool) -> None:
6870
assert all(isinstance(c, str | dict) for c in tool_message.content)
6971

7072
def test_invoke_no_tool_call(self, tool: BaseTool) -> None:
71-
"""Test invoke without ToolCall.
73+
"""Test invoke without `ToolCall`.
7274
73-
If invoked without a ToolCall, the tool can return anything
75+
If invoked without a `ToolCall`, the tool can return anything
7476
but it shouldn't throw an error.
7577
7678
If this test fails, your tool may not be handling the input you defined
@@ -82,9 +84,9 @@ def test_invoke_no_tool_call(self, tool: BaseTool) -> None:
8284
tool.invoke(self.tool_invoke_params_example)
8385

8486
async def test_async_invoke_no_tool_call(self, tool: BaseTool) -> None:
85-
"""Test async invoke without ToolCall.
87+
"""Test async invoke without `ToolCall`.
8688
87-
If ainvoked without a ToolCall, the tool can return anything
89+
If ainvoked without a `ToolCall`, the tool can return anything
8890
but it shouldn't throw an error.
8991
9092
For debugging tips, see `test_invoke_no_tool_call`.

libs/standard-tests/langchain_tests/integration_tests/vectorstores.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def has_async(self) -> bool:
103103
def vectorstore(self) -> VectorStore:
104104
"""Get the vectorstore class to test.
105105
106-
The returned vectorstore should be EMPTY.
106+
The returned vectorstore should be empty.
107107
"""
108108

109109
@property
@@ -398,7 +398,7 @@ def has_get_by_ids(self) -> bool:
398398
assert documents == []
399399

400400
def test_add_documents_documents(self, vectorstore: VectorStore) -> None:
401-
"""Run add_documents tests.
401+
"""Run `add_documents` tests.
402402
403403
??? note "Troubleshooting"
404404
@@ -439,7 +439,7 @@ def has_get_by_ids(self) -> bool:
439439
)
440440

441441
def test_add_documents_with_existing_ids(self, vectorstore: VectorStore) -> None:
442-
"""Test that add_documents with existing IDs is idempotent.
442+
"""Test that `add_documents` with existing IDs is idempotent.
443443
444444
??? note "Troubleshooting"
445445
@@ -754,7 +754,7 @@ def has_get_by_ids(self) -> bool:
754754
async def test_add_documents_documents_async(
755755
self, vectorstore: VectorStore
756756
) -> None:
757-
"""Run add_documents tests.
757+
"""Run `add_documents` tests.
758758
759759
??? note "Troubleshooting"
760760
@@ -797,7 +797,7 @@ def has_get_by_ids(self) -> bool:
797797
async def test_add_documents_with_existing_ids_async(
798798
self, vectorstore: VectorStore
799799
) -> None:
800-
"""Test that add_documents with existing IDs is idempotent.
800+
"""Test that `add_documents` with existing IDs is idempotent.
801801
802802
??? note "Troubleshooting"
803803

0 commit comments

Comments
 (0)