mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 23:54:14 +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,
|
**kwargs: Any,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Determine if a given model call should hit the streaming API."""
|
"""Determine if a given model call should hit the streaming API."""
|
||||||
sync_not_implemented = type(self)._stream == BaseChatModel._stream
|
sync_not_implemented = type(self)._stream == BaseChatModel._stream # noqa: SLF001
|
||||||
async_not_implemented = type(self)._astream == BaseChatModel._astream
|
async_not_implemented = type(self)._astream == BaseChatModel._astream # noqa: SLF001
|
||||||
|
|
||||||
# Check if streaming is implemented.
|
# Check if streaming is implemented.
|
||||||
if (not async_api) and sync_not_implemented:
|
if (not async_api) and sync_not_implemented:
|
||||||
|
@ -522,7 +522,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|||||||
stop: Optional[list[str]] = None,
|
stop: Optional[list[str]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Iterator[str]:
|
) -> 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
|
# model doesn't implement streaming, so use default implementation
|
||||||
yield self.invoke(input, config=config, stop=stop, **kwargs)
|
yield self.invoke(input, config=config, stop=stop, **kwargs)
|
||||||
else:
|
else:
|
||||||
@ -590,8 +590,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> AsyncIterator[str]:
|
) -> AsyncIterator[str]:
|
||||||
if (
|
if (
|
||||||
type(self)._astream is BaseLLM._astream
|
type(self)._astream is BaseLLM._astream # noqa: SLF001
|
||||||
and type(self)._stream is BaseLLM._stream
|
and type(self)._stream is BaseLLM._stream # noqa: SLF001
|
||||||
):
|
):
|
||||||
yield await self.ainvoke(input, config=config, stop=stop, **kwargs)
|
yield await self.ainvoke(input, config=config, stop=stop, **kwargs)
|
||||||
return
|
return
|
||||||
|
@ -131,7 +131,7 @@ class DynamicRunnable(RunnableSerializable[Input, Output]):
|
|||||||
"""
|
"""
|
||||||
runnable: Runnable[Input, Output] = self
|
runnable: Runnable[Input, Output] = self
|
||||||
while isinstance(runnable, DynamicRunnable):
|
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)
|
return runnable, cast("RunnableConfig", config)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -845,7 +845,7 @@ class ChildTool(BaseTool):
|
|||||||
child_config = patch_config(config, callbacks=run_manager.get_child())
|
child_config = patch_config(config, callbacks=run_manager.get_child())
|
||||||
with set_config_context(child_config) as context:
|
with set_config_context(child_config) as context:
|
||||||
func_to_check = (
|
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"):
|
if signature(func_to_check).parameters.get("run_manager"):
|
||||||
tool_kwargs["run_manager"] = 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:
|
def wait_for_all_tracers() -> None:
|
||||||
"""Wait for all tracers to finish."""
|
"""Wait for all tracers to finish."""
|
||||||
if rt._CLIENT is not None:
|
if rt._CLIENT is not None: # noqa: SLF001
|
||||||
rt._CLIENT.flush()
|
rt._CLIENT.flush() # noqa: SLF001
|
||||||
|
|
||||||
|
|
||||||
def get_client() -> Client:
|
def get_client() -> Client:
|
||||||
@ -123,8 +123,8 @@ class LangChainTracer(BaseTracer):
|
|||||||
run.tags = self.tags.copy()
|
run.tags = self.tags.copy()
|
||||||
|
|
||||||
super()._start_trace(run)
|
super()._start_trace(run)
|
||||||
if run._client is None:
|
if run.ls_client is None:
|
||||||
run._client = self.client # type: ignore[misc]
|
run.ls_client = self.client
|
||||||
|
|
||||||
def on_chat_model_start(
|
def on_chat_model_start(
|
||||||
self,
|
self,
|
||||||
|
@ -379,7 +379,7 @@ def _get_key(
|
|||||||
try:
|
try:
|
||||||
# This allows for custom falsy data types
|
# This allows for custom falsy data types
|
||||||
# https://github.com/noahmorrison/chevron/issues/35
|
# 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
|
return resolved_scope
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if resolved_scope in (0, False):
|
if resolved_scope in (0, False):
|
||||||
|
@ -7,7 +7,7 @@ authors = []
|
|||||||
license = {text = "MIT"}
|
license = {text = "MIT"}
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"langsmith<0.4,>=0.1.125",
|
"langsmith<0.4,>=0.1.126",
|
||||||
"tenacity!=8.4.0,<10.0.0,>=8.1.0",
|
"tenacity!=8.4.0,<10.0.0,>=8.1.0",
|
||||||
"jsonpatch<2.0,>=1.33",
|
"jsonpatch<2.0,>=1.33",
|
||||||
"PyYAML>=5.3",
|
"PyYAML>=5.3",
|
||||||
@ -105,7 +105,6 @@ ignore = [
|
|||||||
"ERA",
|
"ERA",
|
||||||
"PLR2004",
|
"PLR2004",
|
||||||
"RUF",
|
"RUF",
|
||||||
"SLF",
|
|
||||||
]
|
]
|
||||||
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
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
|
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_runnable.py" = [ "E501",]
|
||||||
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
|
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
|
||||||
"tests/unit_tests/test_tools.py" = [ "ARG",]
|
"tests/unit_tests/test_tools.py" = [ "ARG",]
|
||||||
"tests/**" = [ "D", "S",]
|
"tests/**" = [ "D", "S", "SLF",]
|
||||||
"scripts/**" = [ "INP", "S",]
|
"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