From 71b361936dc01e6803e83e0d96c0b7193d979dc4 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Tue, 8 Jul 2025 12:55:47 -0400 Subject: [PATCH] ruff: restore stacklevels, disable autofixing (#31919) --- libs/core/pyproject.toml | 2 ++ libs/langchain/langchain/__init__.py | 4 ++-- libs/langchain/langchain/chains/base.py | 2 +- .../langchain/chains/conversational_retrieval/base.py | 2 +- libs/langchain/langchain/chains/llm_checker/base.py | 2 +- libs/langchain/langchain/chains/llm_math/base.py | 2 +- .../langchain/chains/llm_summarization_checker/base.py | 2 +- libs/langchain/langchain/chains/natbot/base.py | 2 +- libs/langchain/langchain/chains/qa_with_sources/vector_db.py | 2 +- libs/langchain/langchain/chains/query_constructor/parser.py | 2 +- libs/langchain/langchain/evaluation/schema.py | 4 ++-- libs/langchain/langchain/indexes/vectorstore.py | 2 +- libs/langchain/langchain/memory/chat_memory.py | 2 +- libs/langchain/langchain/memory/combined.py | 2 +- libs/langchain/pyproject.toml | 1 + libs/partners/anthropic/pyproject.toml | 1 + libs/partners/chroma/pyproject.toml | 1 + libs/partners/deepseek/pyproject.toml | 1 + libs/partners/exa/pyproject.toml | 1 + libs/partners/fireworks/pyproject.toml | 1 + libs/partners/groq/pyproject.toml | 1 + libs/partners/huggingface/pyproject.toml | 1 + libs/partners/mistralai/pyproject.toml | 1 + 23 files changed, 26 insertions(+), 15 deletions(-) diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml index c30453595f3..5d1f0e62fce 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 fd5f8851d4f..edc20ad2b3a 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 fd24eee8e7f..27aec413319 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 a4f17554dba..76c80072732 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 9206b7d2536..a8cbd11f298 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 9830734919d..58ea43c5af5 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 fca7c2ae0f5..7b75b9917cd 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 c1108ce4734..a178c208953 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 bc5509fcdea..566309bde41 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 ab973d948e6..1d0f00a448a 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 402722bca60..588d6c46346 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 e6889160c5e..c1e311feece 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 e94ab712bcf..10a8cda61cc 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 83978bd2629..eb25197ec84 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 3f6f229e808..daec4c27969 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 15dd8409236..db07fa48731 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 c6e82e40ad5..12e043a90ed 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 1777a98b3eb..b68ea275a66 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 80d87e5be4a..8291005c2e6 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 5a9a24c42a9..b16a1237e61 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 3a75d8f66d4..d51eb868813 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 975ae5fa4e4..7c79a6ff2e7 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 131a599fc4b..45e1b86c8df 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/*"]