Skip to content

Commit 50e2b20

Browse files
authored
Merge branch 'wip-v1.0' into typing-dict
2 parents 88472d8 + b494a3c commit 50e2b20

File tree

21 files changed

+149
-245
lines changed

21 files changed

+149
-245
lines changed

docs/docs/contributing/how_to/documentation/style_guide.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Here are some high-level tips on writing a good how-to guide:
7979

8080
### Conceptual guide
8181

82-
LangChain's conceptual guide falls under the **Explanation** quadrant of Diataxis. These guides should cover LangChain terms and concepts
82+
LangChain's conceptual guides fall under the **Explanation** quadrant of Diataxis. These guides should cover LangChain terms and concepts
8383
in a more abstract way than how-to guides or tutorials, targeting curious users interested in
8484
gaining a deeper understanding and insights of the framework. Try to avoid excessively large code examples as the primary goal is to
8585
provide perspective to the user rather than to finish a practical project. These guides should cover **why** things work the way they do.
@@ -105,7 +105,7 @@ Here are some high-level tips on writing a good conceptual guide:
105105
### References
106106

107107
References contain detailed, low-level information that describes exactly what functionality exists and how to use it.
108-
In LangChain, this is mainly our API reference pages, which are populated from docstrings within code.
108+
In LangChain, these are mainly our API reference pages, which are populated from docstrings within code.
109109
References pages are generally not read end-to-end, but are consulted as necessary when a user needs to know
110110
how to use something specific.
111111

@@ -119,25 +119,25 @@ but here are some high-level tips on writing a good docstring:
119119
- Be concise
120120
- Discuss special cases and deviations from a user's expectations
121121
- Go into detail on required inputs and outputs
122-
- Light details on when one might use the feature are fine, but in-depth details belong in other sections.
122+
- Light details on when one might use the feature are fine, but in-depth details belong in other sections
123123

124124
Each category serves a distinct purpose and requires a specific approach to writing and structuring the content.
125125

126126
## General guidelines
127127

128128
Here are some other guidelines you should think about when writing and organizing documentation.
129129

130-
We generally do not merge new tutorials from outside contributors without an actue need.
130+
We generally do not merge new tutorials from outside contributors without an acute need.
131131
We welcome updates as well as new integration docs, how-tos, and references.
132132

133133
### Avoid duplication
134134

135135
Multiple pages that cover the same material in depth are difficult to maintain and cause confusion. There should
136-
be only one (very rarely two), canonical pages for a given concept or feature. Instead, you should link to other guides.
136+
be only one (very rarely two) canonical pages for a given concept or feature. Instead, you should link to other guides.
137137

138138
### Link to other sections
139139

140-
Because sections of the docs do not exist in a vacuum, it is important to link to other sections frequently,
140+
Because sections of the docs do not exist in a vacuum, it is important to link to other sections frequently
141141
to allow a developer to learn more about an unfamiliar topic within the flow of reading.
142142

143143
This includes linking to the API references and conceptual sections!

docs/docs/contributing/tutorials/docs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Sometimes you want to make a small change, like fixing a typo, and the easiest w
3333
- Click the "Commit changes..." button at the top-right corner of the page.
3434
- Give your commit a title like "Fix typo in X section."
3535
- Optionally, write an extended commit description.
36-
- Click "Propose changes"
36+
- Click "Propose changes".
3737

3838
5. **Submit a pull request (PR):**
3939
- GitHub will redirect you to a page where you can create a pull request.

libs/cli/langchain_cli/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""LangChain CLI."""
22

3-
from typing import Annotated, Optional
3+
from typing import Annotated
44

55
import typer
66

@@ -61,11 +61,11 @@ def _main(
6161
def serve(
6262
*,
6363
port: Annotated[
64-
Optional[int],
64+
int | None,
6565
typer.Option(help="The port to run the server on"),
6666
] = None,
6767
host: Annotated[
68-
Optional[str],
68+
str | None,
6969
typer.Option(help="The host to run the server on"),
7070
] = None,
7171
) -> None:

libs/cli/langchain_cli/namespaces/app.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import warnings
77
from pathlib import Path
8-
from typing import Annotated, Optional
8+
from typing import Annotated
99

1010
import typer
1111
import uvicorn
@@ -35,18 +35,18 @@
3535
@app_cli.command()
3636
def new(
3737
name: Annotated[
38-
Optional[str],
38+
str | None,
3939
typer.Argument(
4040
help="The name of the folder to create",
4141
),
4242
] = None,
4343
*,
4444
package: Annotated[
45-
Optional[list[str]],
45+
list[str] | None,
4646
typer.Option(help="Packages to seed the project with"),
4747
] = None,
4848
pip: Annotated[
49-
Optional[bool],
49+
bool | None,
5050
typer.Option(
5151
"--pip/--no-pip",
5252
help="Pip install the template(s) as editable dependencies",
@@ -131,24 +131,24 @@ def new(
131131
@app_cli.command()
132132
def add(
133133
dependencies: Annotated[
134-
Optional[list[str]],
134+
list[str] | None,
135135
typer.Argument(help="The dependency to add"),
136136
] = None,
137137
*,
138138
api_path: Annotated[
139-
Optional[list[str]],
139+
list[str] | None,
140140
typer.Option(help="API paths to add"),
141141
] = None,
142142
project_dir: Annotated[
143-
Optional[Path],
143+
Path | None,
144144
typer.Option(help="The project directory"),
145145
] = None,
146146
repo: Annotated[
147-
Optional[list[str]],
147+
list[str] | None,
148148
typer.Option(help="Install templates from a specific github repo instead"),
149149
] = None,
150150
branch: Annotated[
151-
Optional[list[str]],
151+
list[str] | None,
152152
typer.Option(help="Install templates from a specific branch"),
153153
] = None,
154154
pip: Annotated[
@@ -191,7 +191,7 @@ def add(
191191
)
192192

193193
# group by repo/ref
194-
grouped: dict[tuple[str, Optional[str]], list[DependencySource]] = {}
194+
grouped: dict[tuple[str, str | None], list[DependencySource]] = {}
195195
for dep in parsed_deps:
196196
key_tup = (dep["git"], dep["ref"])
197197
lst = grouped.get(key_tup, [])
@@ -243,7 +243,7 @@ def add(
243243
try:
244244
add_dependencies_to_pyproject_toml(
245245
project_root / "pyproject.toml",
246-
zip(installed_destination_names, installed_destination_paths),
246+
zip(installed_destination_names, installed_destination_paths, strict=False),
247247
)
248248
except Exception:
249249
# Can fail if user modified/removed pyproject.toml
@@ -281,11 +281,11 @@ def add(
281281

282282
imports = [
283283
f"from {e['module']} import {e['attr']} as {name}"
284-
for e, name in zip(installed_exports, chain_names)
284+
for e, name in zip(installed_exports, chain_names, strict=False)
285285
]
286286
routes = [
287287
f'add_routes(app, {name}, path="{path}")'
288-
for name, path in zip(chain_names, api_paths)
288+
for name, path in zip(chain_names, api_paths, strict=False)
289289
]
290290

291291
t = (
@@ -310,7 +310,7 @@ def remove(
310310
api_paths: Annotated[list[str], typer.Argument(help="The API paths to remove")],
311311
*,
312312
project_dir: Annotated[
313-
Optional[Path],
313+
Path | None,
314314
typer.Option(help="The project directory"),
315315
] = None,
316316
) -> None:
@@ -349,15 +349,15 @@ def remove(
349349
def serve(
350350
*,
351351
port: Annotated[
352-
Optional[int],
352+
int | None,
353353
typer.Option(help="The port to run the server on"),
354354
] = None,
355355
host: Annotated[
356-
Optional[str],
356+
str | None,
357357
typer.Option(help="The host to run the server on"),
358358
] = None,
359359
app: Annotated[
360-
Optional[str],
360+
str | None,
361361
typer.Option(help="The app to run, e.g. `app.server:app`"),
362362
] = None,
363363
) -> None:

libs/cli/langchain_cli/namespaces/integration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import subprocess
66
from pathlib import Path
7-
from typing import Annotated, Optional, cast
7+
from typing import Annotated, cast
88

99
import typer
1010
from typing_extensions import TypedDict
@@ -65,22 +65,22 @@ def new(
6565
),
6666
],
6767
name_class: Annotated[
68-
Optional[str],
68+
str | None,
6969
typer.Option(
7070
help="The name of the integration in PascalCase. e.g. `MyIntegration`."
7171
" This is used to name classes like `MyIntegrationVectorStore`",
7272
),
7373
] = None,
7474
src: Annotated[
75-
Optional[list[str]],
75+
list[str] | None,
7676
typer.Option(
7777
help="The name of the single template file to copy."
7878
" e.g. `--src integration_template/chat_models.py "
7979
"--dst my_integration/chat_models.py`. Can be used multiple times.",
8080
),
8181
] = None,
8282
dst: Annotated[
83-
Optional[list[str]],
83+
list[str] | None,
8484
typer.Option(
8585
help="The relative path to the integration package to place the new file in"
8686
". e.g. `my-integration/my_integration.py`",
@@ -166,7 +166,7 @@ def new(
166166
typer.echo(f"File {dst_path} exists.")
167167
raise typer.Exit(code=1)
168168

169-
for src_path, dst_path in zip(src_paths, dst_paths):
169+
for src_path, dst_path in zip(src_paths, dst_paths, strict=False):
170170
shutil.copy(src_path, dst_path)
171171
replace_file(dst_path, cast("dict[str, str]", replacements))
172172

@@ -203,7 +203,7 @@ def create_doc(
203203
),
204204
],
205205
name_class: Annotated[
206-
Optional[str],
206+
str | None,
207207
typer.Option(
208208
help=(
209209
"The PascalCase name of the integration (e.g. `OpenAI`, "

libs/cli/langchain_cli/namespaces/migrate/generate/utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pathlib
77
from pathlib import Path
88
from types import ModuleType
9-
from typing import Any, Optional
9+
10+
from typing_extensions import override
1011

1112
HERE = Path(__file__).parent
1213
# Should bring us to [root]/src
@@ -20,12 +21,13 @@
2021
class ImportExtractor(ast.NodeVisitor):
2122
"""Import extractor."""
2223

23-
def __init__(self, *, from_package: Optional[str] = None) -> None:
24+
def __init__(self, *, from_package: str | None = None) -> None:
2425
"""Extract all imports from the given code, optionally filtering by package."""
25-
self.imports: list = []
26+
self.imports: list[tuple[str, str]] = []
2627
self.package = from_package
2728

28-
def visit_ImportFrom(self, node: ast.ImportFrom) -> None: # noqa: N802
29+
@override
30+
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
2931
if node.module and (
3032
self.package is None or str(node.module).startswith(self.package)
3133
):
@@ -44,7 +46,8 @@ def _get_class_names(code: str) -> list[str]:
4446

4547
# Define a node visitor class to collect class names
4648
class ClassVisitor(ast.NodeVisitor):
47-
def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: N802
49+
@override
50+
def visit_ClassDef(self, node: ast.ClassDef) -> None:
4851
class_names.append(node.name)
4952
self.generic_visit(node)
5053

@@ -54,7 +57,7 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: N802
5457
return class_names
5558

5659

57-
def is_subclass(class_obj: Any, classes_: list[type]) -> bool:
60+
def is_subclass(class_obj: type, classes_: list[type]) -> bool:
5861
"""Check if the given class object is a subclass of any class in list classes."""
5962
return any(
6063
issubclass(class_obj, kls)
@@ -85,7 +88,7 @@ def _get_all_classnames_from_file(file: Path, pkg: str) -> list[tuple[str, str]]
8588
def identify_all_imports_in_file(
8689
file: str,
8790
*,
88-
from_package: Optional[str] = None,
91+
from_package: str | None = None,
8992
) -> list[tuple[str, str]]:
9093
"""Let's also identify all the imports in the given file."""
9194
code = Path(file).read_text(encoding="utf-8")
@@ -144,7 +147,7 @@ def list_init_imports_by_package(pkg_root: str) -> list[tuple[str, str]]:
144147
def find_imports_from_package(
145148
code: str,
146149
*,
147-
from_package: Optional[str] = None,
150+
from_package: str | None = None,
148151
) -> list[tuple[str, str]]:
149152
"""Find imports in code."""
150153
# Parse the code into an AST

libs/cli/langchain_cli/namespaces/migrate/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import rich
66
import typer
7-
from gritql import run # type: ignore[import]
7+
from gritql import run # type: ignore[import-untyped]
88
from typer import Option
99

1010

@@ -68,7 +68,7 @@ def migrate(
6868
final_code = run.apply_pattern(
6969
"langchain_all_migrations()",
7070
args,
71-
grit_dir=get_gritdir_path(),
71+
grit_dir=str(get_gritdir_path()),
7272
)
7373

7474
raise typer.Exit(code=final_code)

libs/cli/langchain_cli/namespaces/template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import subprocess
66
from pathlib import Path
7-
from typing import Annotated, Optional
7+
from typing import Annotated
88

99
import typer
1010
import uvicorn
@@ -88,15 +88,15 @@ def new(
8888
def serve(
8989
*,
9090
port: Annotated[
91-
Optional[int],
91+
int | None,
9292
typer.Option(help="The port to run the server on"),
9393
] = None,
9494
host: Annotated[
95-
Optional[str],
95+
str | None,
9696
typer.Option(help="The host to run the server on"),
9797
] = None,
9898
configurable: Annotated[
99-
Optional[bool],
99+
bool | None,
100100
typer.Option(
101101
"--configurable/--no-configurable",
102102
help="Whether to include a configurable route",
@@ -140,7 +140,7 @@ def serve(
140140

141141

142142
@package_cli.command()
143-
def list(contains: Annotated[Optional[str], typer.Argument()] = None) -> None: # noqa: A001
143+
def list(contains: Annotated[str | None, typer.Argument()] = None) -> None: # noqa: A001
144144
"""List all or search for available templates."""
145145
packages = list_packages(contains=contains)
146146
for package in packages:

libs/cli/langchain_cli/project_template/app/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@app.get("/")
9-
async def redirect_root_to_docs():
9+
async def redirect_root_to_docs() -> RedirectResponse:
1010
return RedirectResponse("/docs")
1111

1212

0 commit comments

Comments
 (0)