Skip to content

Commit ae210c1

Browse files
authored
ruff: add bugbear across packages (#31917)
WIP, other packages will get in next PRs
1 parent 5b3e29f commit ae210c1

File tree

33 files changed

+59
-42
lines changed

33 files changed

+59
-42
lines changed

libs/cli/langchain_cli/namespaces/app.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,22 @@ def add(
134134
typer.Argument(help="The dependency to add"),
135135
] = None,
136136
*,
137-
api_path: Annotated[list[str], typer.Option(help="API paths to add")] = [],
137+
api_path: Annotated[
138+
Optional[list[str]],
139+
typer.Option(help="API paths to add"),
140+
] = None,
138141
project_dir: Annotated[
139142
Optional[Path],
140143
typer.Option(help="The project directory"),
141144
] = None,
142145
repo: Annotated[
143-
list[str],
146+
Optional[list[str]],
144147
typer.Option(help="Install templates from a specific github repo instead"),
145-
] = [],
148+
] = None,
146149
branch: Annotated[
147-
list[str],
150+
Optional[list[str]],
148151
typer.Option(help="Install templates from a specific branch"),
149-
] = [],
152+
] = None,
150153
pip: Annotated[
151154
bool,
152155
typer.Option(
@@ -163,6 +166,12 @@ def add(
163166
langchain app add extraction-openai-functions
164167
langchain app add git+ssh://[email protected]/efriis/simple-pirate.git
165168
"""
169+
if branch is None:
170+
branch = []
171+
if repo is None:
172+
repo = []
173+
if api_path is None:
174+
api_path = []
166175
if not branch and not repo:
167176
warnings.warn(
168177
"Adding templates from the default branch and repo is deprecated."

libs/cli/langchain_cli/namespaces/integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def new(
9090
replacements = _process_name(name)
9191
except ValueError as e:
9292
typer.echo(e)
93-
raise typer.Exit(code=1)
93+
raise typer.Exit(code=1) from None
9494

9595
if name_class:
9696
if not re.match(r"^[A-Z][a-zA-Z0-9]*$", name_class):

libs/cli/langchain_cli/utils/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def parse_dependency_string(
6565
else:
6666
_, post_slash = find_slash.split("/", 1)
6767
if "@" in post_slash or "#" in post_slash:
68-
_, ref = re.split(r"[@#]", post_slash, 1)
68+
_, ref = re.split(r"[@#]", post_slash, maxsplit=1)
6969

7070
# gitstring is everything before that
7171
gitstring = gitstring[: -len(ref) - 1] if ref is not None else gitstring
@@ -159,7 +159,7 @@ def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
159159
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode()).hexdigest()[:8]
160160

161161
removed_protocol = gitstring.split("://")[-1]
162-
removed_basename = re.split(r"[/:]", removed_protocol, 1)[-1]
162+
removed_basename = re.split(r"[/:]", removed_protocol, maxsplit=1)[-1]
163163
removed_extras = removed_basename.split("#")[0]
164164
foldername = re.sub(r"\W", "_", removed_extras)
165165

libs/cli/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ exclude = [
5050
[tool.ruff.lint]
5151
select = [
5252
"A", # flake8-builtins
53+
"B", # flake8-bugbear
5354
"ARG", # flake8-unused-arguments
5455
"ASYNC", # flake8-async
5556
"C4", # flake8-comprehensions
@@ -96,6 +97,7 @@ ignore = [
9697
"D105", # pydocstyle: Missing docstring in magic method
9798
"D107", # pydocstyle: Missing docstring in __init__
9899
"D407", # pydocstyle: Missing-dashed-underline-after-section
100+
"COM812", # Messes with the formatter
99101
]
100102
pyupgrade.keep-runtime-typing = true
101103

libs/langchain/langchain/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ def _warn_on_import(name: str, replacement: Optional[str] = None) -> None:
2929
warnings.warn(
3030
f"Importing {name} from langchain root module is no longer supported. "
3131
f"Please use {replacement} instead.",
32-
stacklevel=3,
32+
stacklevel=2,
3333
)
3434
else:
3535
warnings.warn(
3636
f"Importing {name} from langchain root module is no longer supported.",
37-
stacklevel=3,
37+
stacklevel=2,
3838
)
3939

4040

libs/langchain/langchain/chains/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def raise_callback_manager_deprecation(cls, values: dict) -> Any:
255255
warnings.warn(
256256
"callback_manager is deprecated. Please use callbacks instead.",
257257
DeprecationWarning,
258-
stacklevel=4,
258+
stacklevel=2,
259259
)
260260
values["callbacks"] = values.pop("callback_manager", None)
261261
return values

libs/langchain/langchain/chains/conversational_retrieval/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def raise_deprecation(cls, values: dict) -> Any:
504504
warnings.warn(
505505
"`ChatVectorDBChain` is deprecated - "
506506
"please use `from langchain.chains import ConversationalRetrievalChain`",
507-
stacklevel=4,
507+
stacklevel=2,
508508
)
509509
return values
510510

libs/langchain/langchain/chains/llm_checker/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def raise_deprecation(cls, values: dict) -> Any:
112112
"Directly instantiating an LLMCheckerChain with an llm is deprecated. "
113113
"Please instantiate with question_to_checked_assertions_chain "
114114
"or using the from_llm class method.",
115-
stacklevel=5,
115+
stacklevel=2,
116116
)
117117
if (
118118
"question_to_checked_assertions_chain" not in values

libs/langchain/langchain/chains/llm_math/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def raise_deprecation(cls, values: dict) -> Any:
177177
"Directly instantiating an LLMMathChain with an llm is deprecated. "
178178
"Please instantiate with llm_chain argument or using the from_llm "
179179
"class method.",
180-
stacklevel=5,
180+
stacklevel=2,
181181
)
182182
if "llm_chain" not in values and values["llm"] is not None:
183183
prompt = values.get("prompt", PROMPT)

libs/langchain/langchain/chains/llm_summarization_checker/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def raise_deprecation(cls, values: dict) -> Any:
118118
"Directly instantiating an LLMSummarizationCheckerChain with an llm is "
119119
"deprecated. Please instantiate with"
120120
" sequential_chain argument or using the from_llm class method.",
121-
stacklevel=5,
121+
stacklevel=2,
122122
)
123123
if "sequential_chain" not in values and values["llm"] is not None:
124124
values["sequential_chain"] = _load_sequential_chain(

0 commit comments

Comments
 (0)