Skip to content

Commit 1e101ae

Browse files
cbornetmdrxy
andauthored
chore(langchain): add ruff rules N (#32098)
See https://docs.astral.sh/ruff/rules/#pep8-naming-n Co-authored-by: Mason Daugherty <mason@langchain.dev>
1 parent fe6c415 commit 1e101ae

File tree

18 files changed

+39
-72
lines changed

18 files changed

+39
-72
lines changed

libs/langchain/langchain/agents/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ def __getattr__(name: str) -> Any:
120120
"""Get attr name."""
121121
if name in DEPRECATED_CODE:
122122
# Get directory of langchain package
123-
HERE = Path(__file__).parents[1]
123+
here = Path(__file__).parents[1]
124124
relative_path = as_import_path(
125125
Path(__file__).parent,
126126
suffix=name,
127-
relative_to=HERE,
127+
relative_to=here,
128128
)
129129
old_path = "langchain." + relative_path
130130
new_path = "langchain_experimental." + relative_path

libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from pathlib import Path
21
from typing import Any
32

4-
from langchain_core._api.path import as_import_path
5-
63

74
def __getattr__(name: str) -> Any:
85
"""Get attr name."""
96

107
if name == "create_csv_agent":
11-
# Get directory of langchain package
12-
HERE = Path(__file__).parents[3]
13-
here = as_import_path(Path(__file__).parent, relative_to=HERE)
14-
15-
old_path = "langchain." + here + "." + name
16-
new_path = "langchain_experimental." + here + "." + name
178
msg = (
189
"This agent has been moved to langchain experiment. "
1910
"This agent relies on python REPL tool under the hood, so to use it "
2011
"safely please sandbox the python REPL. "
2112
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
2213
"and https://github.com/langchain-ai/langchain/discussions/11680"
2314
"To keep using this code as is, install langchain experimental and "
24-
f"update your import statement from:\n `{old_path}` to `{new_path}`."
15+
"update your import statement from:\n "
16+
f"`langchain.agents.agent_toolkits.csv.{name}` to "
17+
f"`langchain_experimental.agents.agent_toolkits.{name}`."
2518
)
2619
raise ImportError(msg)
2720
msg = f"{name} does not exist"

libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from pathlib import Path
21
from typing import Any
32

4-
from langchain_core._api.path import as_import_path
5-
63

74
def __getattr__(name: str) -> Any:
85
"""Get attr name."""
96

107
if name == "create_pandas_dataframe_agent":
11-
# Get directory of langchain package
12-
HERE = Path(__file__).parents[3]
13-
here = as_import_path(Path(__file__).parent, relative_to=HERE)
14-
15-
old_path = "langchain." + here + "." + name
16-
new_path = "langchain_experimental." + here + "." + name
178
msg = (
189
"This agent has been moved to langchain experiment. "
1910
"This agent relies on python REPL tool under the hood, so to use it "
2011
"safely please sandbox the python REPL. "
2112
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
2213
"and https://github.com/langchain-ai/langchain/discussions/11680"
2314
"To keep using this code as is, install langchain experimental and "
24-
f"update your import statement from:\n `{old_path}` to `{new_path}`."
15+
"update your import statement from:\n"
16+
f"`langchain.agents.agent_toolkits.pandas.{name}` to "
17+
f"`langchain_experimental.agents.agent_toolkits.{name}`."
2518
)
2619
raise ImportError(msg)
2720
msg = f"{name} does not exist"

libs/langchain/langchain/agents/agent_toolkits/python/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from pathlib import Path
21
from typing import Any
32

4-
from langchain_core._api.path import as_import_path
5-
63

74
def __getattr__(name: str) -> Any:
85
"""Get attr name."""
96

107
if name == "create_python_agent":
11-
# Get directory of langchain package
12-
HERE = Path(__file__).parents[3]
13-
here = as_import_path(Path(__file__).parent, relative_to=HERE)
14-
15-
old_path = "langchain." + here + "." + name
16-
new_path = "langchain_experimental." + here + "." + name
178
msg = (
189
"This agent has been moved to langchain experiment. "
1910
"This agent relies on python REPL tool under the hood, so to use it "
2011
"safely please sandbox the python REPL. "
2112
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
2213
"and https://github.com/langchain-ai/langchain/discussions/11680"
2314
"To keep using this code as is, install langchain experimental and "
24-
f"update your import statement from:\n `{old_path}` to `{new_path}`."
15+
"update your import statement from:\n"
16+
f"`langchain.agents.agent_toolkits.python.{name}` to "
17+
f"`langchain_experimental.agents.agent_toolkits.{name}`."
2518
)
2619
raise ImportError(msg)
2720
msg = f"{name} does not exist"

libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from pathlib import Path
21
from typing import Any
32

4-
from langchain_core._api.path import as_import_path
5-
63

74
def __getattr__(name: str) -> Any:
85
"""Get attr name."""
96

107
if name == "create_spark_dataframe_agent":
11-
# Get directory of langchain package
12-
HERE = Path(__file__).parents[3]
13-
here = as_import_path(Path(__file__).parent, relative_to=HERE)
14-
15-
old_path = "langchain." + here + "." + name
16-
new_path = "langchain_experimental." + here + "." + name
178
msg = (
189
"This agent has been moved to langchain experiment. "
1910
"This agent relies on python REPL tool under the hood, so to use it "
2011
"safely please sandbox the python REPL. "
2112
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
2213
"and https://github.com/langchain-ai/langchain/discussions/11680"
2314
"To keep using this code as is, install langchain experimental and "
24-
f"update your import statement from:\n `{old_path}` to `{new_path}`."
15+
"update your import statement from:\n"
16+
f"`langchain.agents.agent_toolkits.spark.{name}` to "
17+
f"`langchain_experimental.agents.agent_toolkits.{name}`."
2518
)
2619
raise ImportError(msg)
2720
msg = f"{name} does not exist"

libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
from pathlib import Path
21
from typing import Any
32

4-
from langchain_core._api.path import as_import_path
5-
63

74
def __getattr__(name: str) -> Any:
85
"""Get attr name."""
96

107
if name == "create_xorbits_agent":
11-
# Get directory of langchain package
12-
HERE = Path(__file__).parents[3]
13-
here = as_import_path(Path(__file__).parent, relative_to=HERE)
14-
15-
old_path = "langchain." + here + "." + name
16-
new_path = "langchain_experimental." + here + "." + name
178
msg = (
189
"This agent has been moved to langchain experiment. "
1910
"This agent relies on python REPL tool under the hood, so to use it "
2011
"safely please sandbox the python REPL. "
2112
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
2213
"and https://github.com/langchain-ai/langchain/discussions/11680"
2314
"To keep using this code as is, install langchain experimental and "
24-
f"update your import statement from:\n `{old_path}` to `{new_path}`."
15+
"update your import statement from:\n"
16+
f"`langchain.agents.agent_toolkits.xorbits.{name}` to "
17+
f"`langchain_experimental.agents.agent_toolkits.{name}`."
2518
)
2619
raise ImportError(msg)
2720
msg = f"{name} does not exist"

libs/langchain/langchain/callbacks/streamlit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from streamlit.delta_generator import DeltaGenerator
1010

1111

12-
def StreamlitCallbackHandler(
12+
def StreamlitCallbackHandler( # noqa: N802
1313
parent_container: DeltaGenerator,
1414
*,
1515
max_thought_containers: int = 4,

libs/langchain/langchain/chains/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class LLMChain(Chain):
7979

8080
@classmethod
8181
@override
82-
def is_lc_serializable(self) -> bool:
82+
def is_lc_serializable(cls) -> bool:
8383
return True
8484

8585
prompt: BasePromptTemplate

libs/langchain/langchain/chat_models/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ def with_config(
645645
)
646646

647647
@property
648+
@override
648649
def InputType(self) -> TypeAlias:
649650
"""Get the input type for this runnable."""
650651
from langchain_core.prompt_values import (

libs/langchain/langchain/retrievers/self_query/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
9797
Pinecone as CommunityPinecone,
9898
)
9999

100-
BUILTIN_TRANSLATORS: dict[type[VectorStore], type[Visitor]] = {
100+
builtin_translators: dict[type[VectorStore], type[Visitor]] = {
101101
AstraDB: AstraDBTranslator,
102102
PGVector: PGVectorTranslator,
103103
CommunityPinecone: PineconeTranslator,
@@ -128,8 +128,8 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
128128
field.name for field in (vectorstore.meta_fields or []) if field.index
129129
]
130130
return TencentVectorDBTranslator(fields)
131-
if vectorstore.__class__ in BUILTIN_TRANSLATORS:
132-
return BUILTIN_TRANSLATORS[vectorstore.__class__]()
131+
if vectorstore.__class__ in builtin_translators:
132+
return builtin_translators[vectorstore.__class__]()
133133
try:
134134
from langchain_astradb.vectorstores import AstraDBVectorStore
135135
except ImportError:

0 commit comments

Comments
 (0)