mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 14:49:29 +00:00
core: Add ruff rules SLF (#30666)
Add ruff rules SLF: https://docs.astral.sh/ruff/rules/#flake8-self-slf --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
d8a7eda12e
commit
921573e2b7
@ -412,8 +412,8 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
|
||||
**kwargs: Any,
|
||||
) -> bool:
|
||||
"""Determine if a given model call should hit the streaming API."""
|
||||
sync_not_implemented = type(self)._stream == BaseChatModel._stream
|
||||
async_not_implemented = type(self)._astream == BaseChatModel._astream
|
||||
sync_not_implemented = type(self)._stream == BaseChatModel._stream # noqa: SLF001
|
||||
async_not_implemented = type(self)._astream == BaseChatModel._astream # noqa: SLF001
|
||||
|
||||
# Check if streaming is implemented.
|
||||
if (not async_api) and sync_not_implemented:
|
||||
|
@ -522,7 +522,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
stop: Optional[list[str]] = None,
|
||||
**kwargs: Any,
|
||||
) -> Iterator[str]:
|
||||
if type(self)._stream == BaseLLM._stream:
|
||||
if type(self)._stream == BaseLLM._stream: # noqa: SLF001
|
||||
# model doesn't implement streaming, so use default implementation
|
||||
yield self.invoke(input, config=config, stop=stop, **kwargs)
|
||||
else:
|
||||
@ -590,8 +590,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
**kwargs: Any,
|
||||
) -> AsyncIterator[str]:
|
||||
if (
|
||||
type(self)._astream is BaseLLM._astream
|
||||
and type(self)._stream is BaseLLM._stream
|
||||
type(self)._astream is BaseLLM._astream # noqa: SLF001
|
||||
and type(self)._stream is BaseLLM._stream # noqa: SLF001
|
||||
):
|
||||
yield await self.ainvoke(input, config=config, stop=stop, **kwargs)
|
||||
return
|
||||
|
@ -131,7 +131,7 @@ class DynamicRunnable(RunnableSerializable[Input, Output]):
|
||||
"""
|
||||
runnable: Runnable[Input, Output] = self
|
||||
while isinstance(runnable, DynamicRunnable):
|
||||
runnable, config = runnable._prepare(merge_configs(runnable.config, config))
|
||||
runnable, config = runnable._prepare(merge_configs(runnable.config, config)) # noqa: SLF001
|
||||
return runnable, cast("RunnableConfig", config)
|
||||
|
||||
@abstractmethod
|
||||
|
@ -845,7 +845,7 @@ class ChildTool(BaseTool):
|
||||
child_config = patch_config(config, callbacks=run_manager.get_child())
|
||||
with set_config_context(child_config) as context:
|
||||
func_to_check = (
|
||||
self._run if self.__class__._arun is BaseTool._arun else self._arun
|
||||
self._run if self.__class__._arun is BaseTool._arun else self._arun # noqa: SLF001
|
||||
)
|
||||
if signature(func_to_check).parameters.get("run_manager"):
|
||||
tool_kwargs["run_manager"] = run_manager
|
||||
|
@ -50,8 +50,8 @@ def log_error_once(method: str, exception: Exception) -> None:
|
||||
|
||||
def wait_for_all_tracers() -> None:
|
||||
"""Wait for all tracers to finish."""
|
||||
if rt._CLIENT is not None:
|
||||
rt._CLIENT.flush()
|
||||
if rt._CLIENT is not None: # noqa: SLF001
|
||||
rt._CLIENT.flush() # noqa: SLF001
|
||||
|
||||
|
||||
def get_client() -> Client:
|
||||
@ -123,8 +123,8 @@ class LangChainTracer(BaseTracer):
|
||||
run.tags = self.tags.copy()
|
||||
|
||||
super()._start_trace(run)
|
||||
if run._client is None:
|
||||
run._client = self.client # type: ignore[misc]
|
||||
if run.ls_client is None:
|
||||
run.ls_client = self.client
|
||||
|
||||
def on_chat_model_start(
|
||||
self,
|
||||
|
@ -379,7 +379,7 @@ def _get_key(
|
||||
try:
|
||||
# This allows for custom falsy data types
|
||||
# https://github.com/noahmorrison/chevron/issues/35
|
||||
if resolved_scope._CHEVRON_return_scope_when_falsy: # type: ignore[union-attr]
|
||||
if resolved_scope._CHEVRON_return_scope_when_falsy: # type: ignore[union-attr] # noqa: SLF001
|
||||
return resolved_scope
|
||||
except AttributeError:
|
||||
if resolved_scope in (0, False):
|
||||
|
@ -7,7 +7,7 @@ authors = []
|
||||
license = {text = "MIT"}
|
||||
requires-python = ">=3.9"
|
||||
dependencies = [
|
||||
"langsmith<0.4,>=0.1.125",
|
||||
"langsmith<0.4,>=0.1.126",
|
||||
"tenacity!=8.4.0,<10.0.0,>=8.1.0",
|
||||
"jsonpatch<2.0,>=1.33",
|
||||
"PyYAML>=5.3",
|
||||
@ -105,7 +105,6 @@ ignore = [
|
||||
"ERA",
|
||||
"PLR2004",
|
||||
"RUF",
|
||||
"SLF",
|
||||
]
|
||||
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
||||
flake8-annotations.allow-star-arg-any = true
|
||||
@ -132,5 +131,5 @@ classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_ini
|
||||
"tests/unit_tests/runnables/test_runnable.py" = [ "E501",]
|
||||
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
|
||||
"tests/unit_tests/test_tools.py" = [ "ARG",]
|
||||
"tests/**" = [ "D", "S",]
|
||||
"tests/**" = [ "D", "S", "SLF",]
|
||||
"scripts/**" = [ "INP", "S",]
|
||||
|
2410
libs/core/uv.lock
2410
libs/core/uv.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user