Skip to content

The agent engineering platform.

ruff: restore stacklevels, disable autofixing (#31919)

Mason Daugherty71b361936dc0
diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml
index c30453595f..5d1f0e62fc 100644
--- a/libs/core/pyproject.toml
+++ b/libs/core/pyproject.toml
@@ -101,6 +101,8 @@ ignore = [
"PLC0415",
"PLR2004",
]
+unfixable = ["PLW1510",]
+
flake8-annotations.allow-star-arg-any = true
flake8-annotations.mypy-init-return = true
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
diff --git a/libs/langchain/langchain/__init__.py b/libs/langchain/langchain/__init__.py
index fd5f8851d4..edc20ad2b3 100644
--- a/libs/langchain/langchain/__init__.py
+++ b/libs/langchain/langchain/__init__.py
@@ -29,12 +29,12 @@ def _warn_on_import(name: str, replacement: Optional[str] = None) -> None:
warnings.warn(
f"Importing {name} from langchain root module is no longer supported. "
f"Please use {replacement} instead.",
- stacklevel=2,
+ stacklevel=3,
)
else:
warnings.warn(
f"Importing {name} from langchain root module is no longer supported.",
- stacklevel=2,
+ stacklevel=3,
)
diff --git a/libs/langchain/langchain/chains/base.py b/libs/langchain/langchain/chains/base.py
index fd24eee8e7..27aec41331 100644
--- a/libs/langchain/langchain/chains/base.py
+++ b/libs/langchain/langchain/chains/base.py
@@ -255,7 +255,7 @@ class Chain(RunnableSerializable[dict[str, Any], dict[str, Any]], ABC):
warnings.warn(
"callback_manager is deprecated. Please use callbacks instead.",
DeprecationWarning,
- stacklevel=2,
+ stacklevel=4,
)
values["callbacks"] = values.pop("callback_manager", None)
return values
diff --git a/libs/langchain/langchain/chains/conversational_retrieval/base.py b/libs/langchain/langchain/chains/conversational_retrieval/base.py
index a4f17554db..76c8007273 100644
--- a/libs/langchain/langchain/chains/conversational_retrieval/base.py
+++ b/libs/langchain/langchain/chains/conversational_retrieval/base.py
@@ -504,7 +504,7 @@ class ChatVectorDBChain(BaseConversationalRetrievalChain):
warnings.warn(
"`ChatVectorDBChain` is deprecated - "
"please use `from langchain.chains import ConversationalRetrievalChain`",
- stacklevel=2,
+ stacklevel=4,
)
return values
diff --git a/libs/langchain/langchain/chains/llm_checker/base.py b/libs/langchain/langchain/chains/llm_checker/base.py
index 9206b7d253..a8cbd11f29 100644
--- a/libs/langchain/langchain/chains/llm_checker/base.py
+++ b/libs/langchain/langchain/chains/llm_checker/base.py
@@ -112,7 +112,7 @@ class LLMCheckerChain(Chain):
"Directly instantiating an LLMCheckerChain with an llm is deprecated. "
"Please instantiate with question_to_checked_assertions_chain "
"or using the from_llm class method.",
- stacklevel=2,
+ stacklevel=5,
)
if (
"question_to_checked_assertions_chain" not in values
diff --git a/libs/langchain/langchain/chains/llm_math/base.py b/libs/langchain/langchain/chains/llm_math/base.py
index 9830734919..58ea43c5af 100644
--- a/libs/langchain/langchain/chains/llm_math/base.py
+++ b/libs/langchain/langchain/chains/llm_math/base.py
@@ -177,7 +177,7 @@ class LLMMathChain(Chain):
"Directly instantiating an LLMMathChain with an llm is deprecated. "
"Please instantiate with llm_chain argument or using the from_llm "
"class method.",
- stacklevel=2,
+ stacklevel=5,
)
if "llm_chain" not in values and values["llm"] is not None:
prompt = values.get("prompt", PROMPT)
diff --git a/libs/langchain/langchain/chains/llm_summarization_checker/base.py b/libs/langchain/langchain/chains/llm_summarization_checker/base.py
index fca7c2ae0f..7b75b9917c 100644
--- a/libs/langchain/langchain/chains/llm_summarization_checker/base.py
+++ b/libs/langchain/langchain/chains/llm_summarization_checker/base.py
@@ -118,7 +118,7 @@ class LLMSummarizationCheckerChain(Chain):
"Directly instantiating an LLMSummarizationCheckerChain with an llm is "
"deprecated. Please instantiate with"
" sequential_chain argument or using the from_llm class method.",
- stacklevel=2,
+ stacklevel=5,
)
if "sequential_chain" not in values and values["llm"] is not None:
values["sequential_chain"] = _load_sequential_chain(
diff --git a/libs/langchain/langchain/chains/natbot/base.py b/libs/langchain/langchain/chains/natbot/base.py
index c1108ce473..a178c20895 100644
--- a/libs/langchain/langchain/chains/natbot/base.py
+++ b/libs/langchain/langchain/chains/natbot/base.py
@@ -74,7 +74,7 @@ class NatBotChain(Chain):
"Directly instantiating an NatBotChain with an llm is deprecated. "
"Please instantiate with llm_chain argument or using the from_llm "
"class method.",
- stacklevel=2,
+ stacklevel=5,
)
if "llm_chain" not in values and values["llm"] is not None:
values["llm_chain"] = PROMPT | values["llm"] | StrOutputParser()
diff --git a/libs/langchain/langchain/chains/qa_with_sources/vector_db.py b/libs/langchain/langchain/chains/qa_with_sources/vector_db.py
index bc5509fcde..566309bde4 100644
--- a/libs/langchain/langchain/chains/qa_with_sources/vector_db.py
+++ b/libs/langchain/langchain/chains/qa_with_sources/vector_db.py
@@ -77,7 +77,7 @@ class VectorDBQAWithSourcesChain(BaseQAWithSourcesChain):
warnings.warn(
"`VectorDBQAWithSourcesChain` is deprecated - "
"please use `from langchain.chains import RetrievalQAWithSourcesChain`",
- stacklevel=2,
+ stacklevel=5,
)
return values
diff --git a/libs/langchain/langchain/chains/query_constructor/parser.py b/libs/langchain/langchain/chains/query_constructor/parser.py
index ab973d948e..1d0f00a448 100644
--- a/libs/langchain/langchain/chains/query_constructor/parser.py
+++ b/libs/langchain/langchain/chains/query_constructor/parser.py
@@ -162,7 +162,7 @@ class QueryTransformer(Transformer):
warnings.warn(
"Dates are expected to be provided in ISO 8601 date format "
"(YYYY-MM-DD).",
- stacklevel=2,
+ stacklevel=3,
)
return {"date": item, "type": "date"}
diff --git a/libs/langchain/langchain/evaluation/schema.py b/libs/langchain/langchain/evaluation/schema.py
index 402722bca6..588d6c4634 100644
--- a/libs/langchain/langchain/evaluation/schema.py
+++ b/libs/langchain/langchain/evaluation/schema.py
@@ -124,12 +124,12 @@ class _EvalArgsMixin:
msg = f"{self.__class__.__name__} requires an input string."
raise ValueError(msg)
if input_ is not None and not self.requires_input:
- warn(self._skip_input_warning, stacklevel=2)
+ warn(self._skip_input_warning, stacklevel=3)
if self.requires_reference and reference is None:
msg = f"{self.__class__.__name__} requires a reference string."
raise ValueError(msg)
if reference is not None and not self.requires_reference:
- warn(self._skip_reference_warning, stacklevel=2)
+ warn(self._skip_reference_warning, stacklevel=3)
class StringEvaluator(_EvalArgsMixin, ABC):
diff --git a/libs/langchain/langchain/indexes/vectorstore.py b/libs/langchain/langchain/indexes/vectorstore.py
index e6889160c5..c1e311feec 100644
--- a/libs/langchain/langchain/indexes/vectorstore.py
+++ b/libs/langchain/langchain/indexes/vectorstore.py
@@ -183,7 +183,7 @@ def _get_in_memory_vectorstore() -> type[VectorStore]:
"Using InMemoryVectorStore as the default vectorstore."
"This memory store won't persist data. You should explicitly"
"specify a vectorstore when using VectorstoreIndexCreator",
- stacklevel=2,
+ stacklevel=3,
)
return InMemoryVectorStore
diff --git a/libs/langchain/langchain/memory/chat_memory.py b/libs/langchain/langchain/memory/chat_memory.py
index e94ab712bc..10a8cda61c 100644
--- a/libs/langchain/langchain/memory/chat_memory.py
+++ b/libs/langchain/langchain/memory/chat_memory.py
@@ -58,7 +58,7 @@ class BaseChatMemory(BaseMemory, ABC):
f"'{self.__class__.__name__}' got multiple output keys:"
f" {outputs.keys()}. The default 'output' key is being used."
f" If this is not desired, please manually set 'output_key'.",
- stacklevel=2,
+ stacklevel=3,
)
else:
msg = (
diff --git a/libs/langchain/langchain/memory/combined.py b/libs/langchain/langchain/memory/combined.py
index 83978bd262..eb25197ec8 100644
--- a/libs/langchain/langchain/memory/combined.py
+++ b/libs/langchain/langchain/memory/combined.py
@@ -42,7 +42,7 @@ class CombinedMemory(BaseMemory):
"When using CombinedMemory, "
"input keys should be so the input is known. "
f" Was not set on {val}",
- stacklevel=2,
+ stacklevel=5,
)
return value
diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml
index 3f6f229e80..daec4c2796 100644
--- a/libs/langchain/pyproject.toml
+++ b/libs/langchain/pyproject.toml
@@ -198,6 +198,7 @@ ignore = [
"SLF001", # Private member access
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
pydocstyle.convention = "google"
pyupgrade.keep-runtime-typing = true
diff --git a/libs/partners/anthropic/pyproject.toml b/libs/partners/anthropic/pyproject.toml
index 15dd840923..db07fa4873 100644
--- a/libs/partners/anthropic/pyproject.toml
+++ b/libs/partners/anthropic/pyproject.toml
@@ -114,6 +114,7 @@ ignore = [
"UP045", # non-pep604-annotation-optional
"SIM105", # Rarely useful
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/chroma/pyproject.toml b/libs/partners/chroma/pyproject.toml
index c6e82e40ad..12e043a90e 100644
--- a/libs/partners/chroma/pyproject.toml
+++ b/libs/partners/chroma/pyproject.toml
@@ -109,6 +109,7 @@ ignore = [
"D107", # Missing docstring in __init__
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/deepseek/pyproject.toml b/libs/partners/deepseek/pyproject.toml
index 1777a98b3e..b68ea275a6 100644
--- a/libs/partners/deepseek/pyproject.toml
+++ b/libs/partners/deepseek/pyproject.toml
@@ -95,6 +95,7 @@ ignore = [
"D107", # Missing docstring in __init__
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/exa/pyproject.toml b/libs/partners/exa/pyproject.toml
index 80d87e5be4..8291005c2e 100644
--- a/libs/partners/exa/pyproject.toml
+++ b/libs/partners/exa/pyproject.toml
@@ -100,6 +100,7 @@ ignore = [
"SLF001", # Private member access
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/fireworks/pyproject.toml b/libs/partners/fireworks/pyproject.toml
index 5a9a24c42a..b16a1237e6 100644
--- a/libs/partners/fireworks/pyproject.toml
+++ b/libs/partners/fireworks/pyproject.toml
@@ -104,6 +104,7 @@ ignore = [
"SLF001", # Private member access
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/groq/pyproject.toml b/libs/partners/groq/pyproject.toml
index 3a75d8f66d..d51eb86881 100644
--- a/libs/partners/groq/pyproject.toml
+++ b/libs/partners/groq/pyproject.toml
@@ -97,6 +97,7 @@ ignore = [
"SLF001", # Private member access
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/huggingface/pyproject.toml b/libs/partners/huggingface/pyproject.toml
index 975ae5fa4e..7c79a6ff2e 100644
--- a/libs/partners/huggingface/pyproject.toml
+++ b/libs/partners/huggingface/pyproject.toml
@@ -112,6 +112,7 @@ ignore = [
"SLF001", # Private member access
"UP007", # pyupgrade: non-pep604-annotation-union
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]
diff --git a/libs/partners/mistralai/pyproject.toml b/libs/partners/mistralai/pyproject.toml
index 131a599fc4..45e1b86c8d 100644
--- a/libs/partners/mistralai/pyproject.toml
+++ b/libs/partners/mistralai/pyproject.toml
@@ -104,6 +104,7 @@ ignore = [
"UP007", # pyupgrade: non-pep604-annotation-union
"UP045", # pyupgrade: non-pep604-annotation-optional
]
+unfixable = ["B028"] # People should intentionally tune the stacklevel
[tool.coverage.run]
omit = ["tests/*"]