ref: Add more ruff rules (#3994)

Add more ruff rules
This commit is contained in:
Christophe Bornet 2024-10-03 10:55:49 +02:00 • committed by GitHub
commit a3a950c290
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 51 additions and 48 deletions

View file

View file

@ -521,7 +521,7 @@ async def process(
""" """
# Raise a depreciation warning # Raise a depreciation warning
logger.warning( logger.warning(
"The /process endpoint is deprecated and will be removed in a future version. " "Please use /run instead." "The /process endpoint is deprecated and will be removed in a future version. Please use /run instead."
) )
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,

View file

@ -15,30 +15,37 @@ followed by a newline with a space.
import re import re
import shlex import shlex
from collections import OrderedDict, namedtuple from collections import OrderedDict
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from typing import NamedTuple
ParsedArgs = namedtuple(
"ParsedArgs",
[
"command",
"url",
"data",
"data_binary",
"method",
"headers",
"compressed",
"insecure",
"user",
"include",
"silent",
"proxy",
"proxy_user",
"cookies",
],
)
ParsedContext = namedtuple("ParsedContext", ["method", "url", "data", "headers", "cookies", "verify", "auth", "proxy"]) class ParsedArgs(NamedTuple):
command: str | None
url: str | None
data: str | None
data_binary: str | None
method: str
headers: list[str]
compressed: bool
insecure: bool
user: tuple[str, str]
include: bool
silent: bool
proxy: str | None
proxy_user: str | None
cookies: dict[str, str]
class ParsedContext(NamedTuple):
method: str
url: str
data: str | None
headers: dict[str, str]
cookies: dict[str, str]
verify: bool
auth: tuple[str, str] | None
proxy: dict[str, str] | None
def normalize_newlines(multiline_text): def normalize_newlines(multiline_text):

View file

@ -125,7 +125,7 @@ class ChatLiteLLMModelComponent(LCModelComponent):
litellm.drop_params = True litellm.drop_params = True
litellm.set_verbose = self.verbose litellm.set_verbose = self.verbose
except ImportError as e: except ImportError as e:
msg = "Could not import litellm python package. " "Please install it with `pip install litellm`" msg = "Could not import litellm python package. Please install it with `pip install litellm`"
raise ChatLiteLLMException(msg) from e raise ChatLiteLLMException(msg) from e
# Remove empty keys # Remove empty keys
if "" in self.kwargs: if "" in self.kwargs:

View file

@ -57,9 +57,7 @@ class FirecrawlCrawlApi(CustomComponent):
try: try:
from firecrawl.firecrawl import FirecrawlApp # type: ignore from firecrawl.firecrawl import FirecrawlApp # type: ignore
except ImportError as e: except ImportError as e:
msg = ( msg = "Could not import firecrawl integration package. Please install it with `pip install firecrawl-py`."
"Could not import firecrawl integration package. " "Please install it with `pip install firecrawl-py`."
)
raise ImportError(msg) from e raise ImportError(msg) from e
crawler_options_dict = crawlerOptions.__dict__["data"]["text"] if crawlerOptions else {} crawler_options_dict = crawlerOptions.__dict__["data"]["text"] if crawlerOptions else {}

View file

@ -50,9 +50,7 @@ class FirecrawlScrapeApi(CustomComponent):
try: try:
from firecrawl.firecrawl import FirecrawlApp # type: ignore from firecrawl.firecrawl import FirecrawlApp # type: ignore
except ImportError as e: except ImportError as e:
msg = ( msg = "Could not import firecrawl integration package. Please install it with `pip install firecrawl-py`."
"Could not import firecrawl integration package. " "Please install it with `pip install firecrawl-py`."
)
raise ImportError(msg) from e raise ImportError(msg) from e
extractor_options_dict = extractorOptions.__dict__["data"]["text"] if extractorOptions else {} extractor_options_dict = extractorOptions.__dict__["data"]["text"] if extractorOptions else {}

View file

@ -55,7 +55,7 @@ class CassandraChatMemory(LCChatMemoryComponent):
try: try:
import cassio import cassio
except ImportError as e: except ImportError as e:
msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." msg = "Could not import cassio integration package. Please install it with `pip install cassio`."
raise ImportError(msg) from e raise ImportError(msg) from e
from uuid import UUID from uuid import UUID

View file

@ -35,7 +35,7 @@ class ZepChatMemory(LCChatMemoryComponent):
zep_python.zep_client.API_BASE_PATH = self.api_base_path zep_python.zep_client.API_BASE_PATH = self.api_base_path
except ImportError as e: except ImportError as e:
msg = "Could not import zep-python package. " "Please install it with `pip install zep-python`." msg = "Could not import zep-python package. Please install it with `pip install zep-python`."
raise ImportError(msg) from e raise ImportError(msg) from e
zep_client = ZepClient(api_url=self.url, api_key=self.api_key) zep_client = ZepClient(api_url=self.url, api_key=self.api_key)

View file

@ -48,7 +48,7 @@ class JSONCleaner(Component):
try: try:
from json_repair import repair_json # type: ignore from json_repair import repair_json # type: ignore
except ImportError as e: except ImportError as e:
msg = "Could not import the json_repair package." "Please install it with `pip install json_repair`." msg = "Could not import the json_repair package. Please install it with `pip install json_repair`."
raise ImportError(msg) from e raise ImportError(msg) from e
"""Clean the input JSON string based on provided options and return the cleaned JSON string.""" """Clean the input JSON string based on provided options and return the cleaned JSON string."""

View file

@ -137,7 +137,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
import cassio import cassio
from langchain_community.utilities.cassandra import SetupMode from langchain_community.utilities.cassandra import SetupMode
except ImportError as e: except ImportError as e:
msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." msg = "Could not import cassio integration package. Please install it with `pip install cassio`."
raise ImportError(msg) from e raise ImportError(msg) from e
from uuid import UUID from uuid import UUID

View file

@ -126,7 +126,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
import cassio import cassio
from langchain_community.utilities.cassandra import SetupMode from langchain_community.utilities.cassandra import SetupMode
except ImportError as e: except ImportError as e:
msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." msg = "Could not import cassio integration package. Please install it with `pip install cassio`."
raise ImportError(msg) from e raise ImportError(msg) from e
database_ref = self.database_ref database_ref = self.database_ref

View file

@ -107,9 +107,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
from chromadb import Client from chromadb import Client
from langchain_chroma import Chroma from langchain_chroma import Chroma
except ImportError as e: except ImportError as e:
msg = ( msg = "Could not import Chroma integration package. Please install it with `pip install langchain-chroma`."
"Could not import Chroma integration package. " "Please install it with `pip install langchain-chroma`."
)
raise ImportError(msg) from e raise ImportError(msg) from e
# Chroma settings # Chroma settings
chroma_settings = None chroma_settings = None

View file

@ -191,7 +191,7 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
from astrapy.authentication import UsernamePasswordTokenProvider from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment from astrapy.constants import Environment
except ImportError as e: except ImportError as e:
msg = "Could not import astrapy integration package. " "Please install it with `pip install astrapy`." msg = "Could not import astrapy integration package. Please install it with `pip install astrapy`."
raise ImportError(msg) from e raise ImportError(msg) from e
try: try:

View file

@ -74,9 +74,7 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent):
try: try:
from langchain_milvus.vectorstores import Milvus as LangchainMilvus from langchain_milvus.vectorstores import Milvus as LangchainMilvus
except ImportError as e: except ImportError as e:
msg = ( msg = "Could not import Milvus integration package. Please install it with `pip install langchain-milvus`."
"Could not import Milvus integration package. " "Please install it with `pip install langchain-milvus`."
)
raise ImportError(msg) from e raise ImportError(msg) from e
self.connection_args.update(uri=self.uri, token=self.password) self.connection_args.update(uri=self.uri, token=self.password)
milvus_store = LangchainMilvus( milvus_store = LangchainMilvus(

View file

@ -572,9 +572,7 @@ class Component(CustomComponent):
except KeyError as e: except KeyError as e:
close_match = find_closest_match(name, list(template.keys())) close_match = find_closest_match(name, list(template.keys()))
if close_match: if close_match:
msg = ( msg = f"Parameter '{name}' not found in {self.__class__.__name__}. Did you mean '{close_match}'?"
f"Parameter '{name}' not found in {self.__class__.__name__}. " f"Did you mean '{close_match}'?"
)
raise ValueError(msg) from e raise ValueError(msg) from e
msg = f"Parameter {name} not found in {self.__class__.__name__}. " msg = f"Parameter {name} not found in {self.__class__.__name__}. "
raise ValueError(msg) from e raise ValueError(msg) from e

View file

@ -89,7 +89,7 @@ class Edge:
if not self.valid_handles: if not self.valid_handles:
logger.debug(self.source_handle) logger.debug(self.source_handle)
logger.debug(self.target_handle) logger.debug(self.target_handle)
msg = f"Edge between {source.display_name} and {target.display_name} " f"has invalid handles" msg = f"Edge between {source.display_name} and {target.display_name} has invalid handles"
raise ValueError(msg) raise ValueError(msg)
def _legacy_validate_handles(self, source, target) -> None: def _legacy_validate_handles(self, source, target) -> None:
@ -103,7 +103,7 @@ class Edge:
if not self.valid_handles: if not self.valid_handles:
logger.debug(self.source_handle) logger.debug(self.source_handle)
logger.debug(self.target_handle) logger.debug(self.target_handle)
msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has invalid handles" msg = f"Edge between {source.vertex_type} and {target.vertex_type} has invalid handles"
raise ValueError(msg) raise ValueError(msg)
def __setstate__(self, state): def __setstate__(self, state):
@ -160,7 +160,7 @@ class Edge:
if no_matched_type: if no_matched_type:
logger.debug(self.source_types) logger.debug(self.source_types)
logger.debug(self.target_reqs) logger.debug(self.target_reqs)
msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has no matched type. " msg = f"Edge between {source.vertex_type} and {target.vertex_type} has no matched type."
raise ValueError(msg) raise ValueError(msg)
def _legacy_validate_edge(self, source, target) -> None: def _legacy_validate_edge(self, source, target) -> None:
@ -182,7 +182,7 @@ class Edge:
if no_matched_type: if no_matched_type:
logger.debug(self.source_types) logger.debug(self.source_types)
logger.debug(self.target_reqs) logger.debug(self.target_reqs)
msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has no matched type" msg = f"Edge between {source.vertex_type} and {target.vertex_type} has no matched type"
raise ValueError(msg) raise ValueError(msg)
def __repr__(self) -> str: def __repr__(self) -> str:

View file

@ -168,13 +168,18 @@ select = [
"FA", "FA",
"FLY", "FLY",
"FURB", "FURB",
"G",
"I", "I",
"ICN", "ICN",
"INT", "INT",
"INP",
"ISC",
"LOG", "LOG",
"NPY", "NPY",
"PD", "PD",
"PIE", "PIE",
"PT",
"PYI",
"Q", "Q",
"RET", "RET",
"RSE", "RSE",
@ -188,6 +193,7 @@ select = [
] ]
ignore = [ ignore = [
"COM812", # Messes with the formatter "COM812", # Messes with the formatter
"ISC001", # Messes with the formatter
] ]
[tool.uv] [tool.uv]