ref: Add ruff rules for pygrep-hooks (PGH) (#4042)
Add ruff rules for pygrep-hooks (PGH)
This commit is contained in:
parent
da6b5eadbc
commit
d4818a37ee
109 changed files with 220 additions and 222 deletions
|
|
@ -10,8 +10,8 @@ import click
|
|||
import httpx
|
||||
import typer
|
||||
from dotenv import load_dotenv
|
||||
from multiprocess import cpu_count # type: ignore
|
||||
from multiprocess.context import Process # type: ignore
|
||||
from multiprocess import cpu_count
|
||||
from multiprocess.context import Process
|
||||
from packaging import version as pkg_version
|
||||
from rich import box
|
||||
from rich import print as rprint
|
||||
|
|
@ -530,7 +530,7 @@ def api_key(
|
|||
|
||||
def api_key_banner(unmasked_api_key):
|
||||
is_mac = platform.system() == "Darwin"
|
||||
import pyperclip # type: ignore
|
||||
import pyperclip
|
||||
|
||||
pyperclip.copy(unmasked_api_key.api_key)
|
||||
panel = Panel(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from alembic import context
|
|||
from loguru import logger
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from langflow.services.database.models import * # noqa
|
||||
from langflow.services.database.models import *
|
||||
from langflow.services.database.service import SQLModel
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
|
|
|
|||
|
|
@ -259,9 +259,9 @@ def parse_value(value: Any, input_type: str) -> Any:
|
|||
|
||||
async def cascade_delete_flow(session: Session, flow: Flow):
|
||||
try:
|
||||
session.exec(delete(TransactionTable).where(TransactionTable.flow_id == flow.id)) # type: ignore
|
||||
session.exec(delete(VertexBuildTable).where(VertexBuildTable.flow_id == flow.id)) # type: ignore
|
||||
session.exec(delete(Flow).where(Flow.id == flow.id)) # type: ignore
|
||||
session.exec(delete(TransactionTable).where(TransactionTable.flow_id == flow.id))
|
||||
session.exec(delete(VertexBuildTable).where(VertexBuildTable.flow_id == flow.id))
|
||||
session.exec(delete(Flow).where(Flow.id == flow.id))
|
||||
except Exception as e:
|
||||
msg = f"Unable to cascade delete flow: ${flow.id}"
|
||||
raise RuntimeError(msg, e) from e
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Code(BaseModel):
|
|||
|
||||
|
||||
class FrontendNodeRequest(FrontendNode):
|
||||
template: dict # type: ignore
|
||||
template: dict # type: ignore[assignment]
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ async def simple_run_flow(
|
|||
if input_request.output_type == "debug"
|
||||
or (
|
||||
vertex.is_output
|
||||
and (input_request.output_type == "any" or input_request.output_type in vertex.id.lower()) # type: ignore
|
||||
and (input_request.output_type == "any" or input_request.output_type in vertex.id.lower()) # type: ignore[operator]
|
||||
)
|
||||
]
|
||||
task_result, session_id = await run_graph_internal(
|
||||
|
|
@ -346,7 +346,7 @@ async def webhook_run_flow(
|
|||
)
|
||||
|
||||
logger.debug("Starting background task")
|
||||
background_tasks.add_task( # type: ignore
|
||||
background_tasks.add_task(
|
||||
simple_run_flow_task,
|
||||
flow=flow,
|
||||
input_request=input_request,
|
||||
|
|
@ -659,7 +659,7 @@ def get_config():
|
|||
try:
|
||||
from langflow.services.deps import get_settings_service
|
||||
|
||||
settings_service: SettingsService = get_settings_service() # type: ignore
|
||||
settings_service: SettingsService = get_settings_service()
|
||||
return settings_service.settings.model_dump()
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ async def download_profile_picture(
|
|||
try:
|
||||
extension = file_name.split(".")[-1]
|
||||
config_dir = get_storage_service().settings_service.settings.config_dir
|
||||
config_path = Path(config_dir) # type: ignore
|
||||
config_path = Path(config_dir) # type: ignore[arg-type]
|
||||
folder_path = config_path / "profile_pictures" / folder_name
|
||||
content_type = build_content_type_from_extension(extension)
|
||||
file_content = await storage_service.get_file(flow_id=folder_path, file_name=file_name) # type: ignore
|
||||
file_content = await storage_service.get_file(flow_id=folder_path, file_name=file_name) # type: ignore[arg-type]
|
||||
return StreamingResponse(BytesIO(file_content), media_type=content_type)
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -142,13 +142,13 @@ async def download_profile_picture(
|
|||
async def list_profile_pictures(storage_service: Annotated[StorageService, Depends(get_storage_service)]):
|
||||
try:
|
||||
config_dir = get_storage_service().settings_service.settings.config_dir
|
||||
config_path = Path(config_dir) # type: ignore
|
||||
config_path = Path(config_dir) # type: ignore[arg-type]
|
||||
|
||||
people_path = config_path / "profile_pictures/People"
|
||||
space_path = config_path / "profile_pictures/Space"
|
||||
|
||||
people = await storage_service.list_files(flow_id=people_path) # type: ignore
|
||||
space = await storage_service.list_files(flow_id=space_path) # type: ignore
|
||||
people = await storage_service.list_files(flow_id=people_path) # type: ignore[arg-type]
|
||||
space = await storage_service.list_files(flow_id=space_path) # type: ignore[arg-type]
|
||||
|
||||
files = [f"People/{i}" for i in people]
|
||||
files += [f"Space/{i}" for i in space]
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def create_flow(
|
|||
# based on the highest number found
|
||||
if session.exec(select(Flow).where(Flow.name == flow.name).where(Flow.user_id == current_user.id)).first():
|
||||
flows = session.exec(
|
||||
select(Flow).where(Flow.name.like(f"{flow.name} (%")).where(Flow.user_id == current_user.id) # type: ignore
|
||||
select(Flow).where(Flow.name.like(f"{flow.name} (%")).where(Flow.user_id == current_user.id) # type: ignore[attr-defined]
|
||||
).all()
|
||||
if flows:
|
||||
extract_number = re.compile(r"\((\d+)\)$")
|
||||
|
|
@ -74,14 +74,14 @@ def create_flow(
|
|||
):
|
||||
flows = session.exec(
|
||||
select(Flow)
|
||||
.where(Flow.endpoint_name.like(f"{flow.endpoint_name}-%")) # type: ignore
|
||||
.where(Flow.endpoint_name.like(f"{flow.endpoint_name}-%")) # type: ignore[union-attr]
|
||||
.where(Flow.user_id == current_user.id)
|
||||
).all()
|
||||
if flows:
|
||||
# The endpoitn name is like "my-endpoint","my-endpoint-1", "my-endpoint-2"
|
||||
# so we need to get the highest number and add 1
|
||||
# we need to get the last part of the endpoint name
|
||||
numbers = [int(flow.endpoint_name.split("-")[-1]) for flow in flows] # type: ignore
|
||||
numbers = [int(flow.endpoint_name.split("-")[-1]) for flow in flows]
|
||||
flow.endpoint_name = f"{flow.endpoint_name}-{max(numbers) + 1}"
|
||||
else:
|
||||
flow.endpoint_name = f"{flow.endpoint_name}-1"
|
||||
|
|
@ -148,16 +148,16 @@ def read_flows(
|
|||
auth_settings = settings_service.auth_settings
|
||||
if auth_settings.AUTO_LOGIN:
|
||||
stmt = select(Flow).where(
|
||||
(Flow.user_id == None) | (Flow.user_id == current_user.id) # noqa
|
||||
(Flow.user_id == None) | (Flow.user_id == current_user.id) # noqa: E711
|
||||
)
|
||||
if components_only:
|
||||
stmt = stmt.where(Flow.is_component == True) # noqa
|
||||
stmt = stmt.where(Flow.is_component == True) # noqa: E712
|
||||
flows = session.exec(stmt).all()
|
||||
|
||||
else:
|
||||
flows = current_user.flows
|
||||
|
||||
flows = validate_is_component(flows) # type: ignore
|
||||
flows = validate_is_component(flows)
|
||||
if components_only:
|
||||
flows = [flow for flow in flows if flow.is_component]
|
||||
flow_ids = [flow.id for flow in flows]
|
||||
|
|
@ -169,7 +169,7 @@ def read_flows(
|
|||
example_flows = folder.flows if folder else []
|
||||
for example_flow in example_flows:
|
||||
if example_flow.id not in flow_ids:
|
||||
flows.append(example_flow) # type: ignore
|
||||
flows.append(example_flow)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ def read_flow(
|
|||
# If auto login is enable user_id can be current_user.id or None
|
||||
# so write an OR
|
||||
stmt = stmt.where(
|
||||
(Flow.user_id == current_user.id) | (Flow.user_id == None) # noqa
|
||||
(Flow.user_id == current_user.id) | (Flow.user_id == None) # noqa: E711
|
||||
)
|
||||
if user_flow := session.exec(stmt).first():
|
||||
return user_flow
|
||||
|
|
@ -369,7 +369,7 @@ async def download_multiple_file(
|
|||
db: Annotated[Session, Depends(get_session)],
|
||||
):
|
||||
"""Download all flows as a zip file."""
|
||||
flows = db.exec(select(Flow).where(and_(Flow.user_id == user.id, Flow.id.in_(flow_ids)))).all() # type: ignore
|
||||
flows = db.exec(select(Flow).where(and_(Flow.user_id == user.id, Flow.id.in_(flow_ids)))).all() # type: ignore[attr-defined]
|
||||
|
||||
if not flows:
|
||||
raise HTTPException(status_code=404, detail="No flows found.")
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def create_folder(
|
|||
).first():
|
||||
folder_results = session.exec(
|
||||
select(Folder).where(
|
||||
Folder.name.like(f"{new_folder.name}%"), # type: ignore
|
||||
Folder.name.like(f"{new_folder.name}%"), # type: ignore[attr-defined]
|
||||
Folder.user_id == current_user.id,
|
||||
)
|
||||
)
|
||||
|
|
@ -62,14 +62,14 @@ def create_folder(
|
|||
|
||||
if folder.components_list:
|
||||
update_statement_components = (
|
||||
update(Flow).where(Flow.id.in_(folder.components_list)).values(folder_id=new_folder.id) # type: ignore
|
||||
update(Flow).where(Flow.id.in_(folder.components_list)).values(folder_id=new_folder.id) # type: ignore[attr-defined]
|
||||
)
|
||||
session.exec(update_statement_components) # type: ignore
|
||||
session.exec(update_statement_components)
|
||||
session.commit()
|
||||
|
||||
if folder.flows_list:
|
||||
update_statement_flows = update(Flow).where(Flow.id.in_(folder.flows_list)).values(folder_id=new_folder.id) # type: ignore
|
||||
session.exec(update_statement_flows) # type: ignore
|
||||
update_statement_flows = update(Flow).where(Flow.id.in_(folder.flows_list)).values(folder_id=new_folder.id) # type: ignore[attr-defined]
|
||||
session.exec(update_statement_flows)
|
||||
session.commit()
|
||||
|
||||
return new_folder
|
||||
|
|
@ -86,7 +86,7 @@ def read_folders(
|
|||
try:
|
||||
folders = session.exec(
|
||||
select(Folder).where(
|
||||
or_(Folder.user_id == current_user.id, Folder.user_id == None) # type: ignore # noqa: E711
|
||||
or_(Folder.user_id == current_user.id, Folder.user_id == None) # noqa: E711
|
||||
)
|
||||
).all()
|
||||
return sorted(folders, key=lambda x: x.name != DEFAULT_FOLDER_NAME)
|
||||
|
|
@ -152,16 +152,16 @@ def update_folder(
|
|||
my_collection_folder = session.exec(select(Folder).where(Folder.name == DEFAULT_FOLDER_NAME)).first()
|
||||
if my_collection_folder:
|
||||
update_statement_my_collection = (
|
||||
update(Flow).where(Flow.id.in_(excluded_flows)).values(folder_id=my_collection_folder.id) # type: ignore
|
||||
update(Flow).where(Flow.id.in_(excluded_flows)).values(folder_id=my_collection_folder.id) # type: ignore[attr-defined]
|
||||
)
|
||||
session.exec(update_statement_my_collection) # type: ignore
|
||||
session.exec(update_statement_my_collection)
|
||||
session.commit()
|
||||
|
||||
if concat_folder_components:
|
||||
update_statement_components = (
|
||||
update(Flow).where(Flow.id.in_(concat_folder_components)).values(folder_id=existing_folder.id) # type: ignore
|
||||
update(Flow).where(Flow.id.in_(concat_folder_components)).values(folder_id=existing_folder.id) # type: ignore[attr-defined]
|
||||
)
|
||||
session.exec(update_statement_components) # type: ignore
|
||||
session.exec(update_statement_components)
|
||||
session.commit()
|
||||
|
||||
return existing_folder
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ async def delete_messages(
|
|||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
):
|
||||
try:
|
||||
session.exec(delete(MessageTable).where(MessageTable.id.in_(message_ids))) # type: ignore
|
||||
session.exec(delete(MessageTable).where(MessageTable.id.in_(message_ids))) # type: ignore[attr-defined]
|
||||
session.commit()
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||
|
|
@ -147,7 +147,7 @@ async def delete_messages_session(
|
|||
session: Annotated[Session, Depends(get_session)],
|
||||
):
|
||||
try:
|
||||
session.exec( # type: ignore
|
||||
session.exec(
|
||||
delete(MessageTable)
|
||||
.where(col(MessageTable.session_id) == session_id)
|
||||
.execution_options(synchronize_session="fetch")
|
||||
|
|
|
|||
|
|
@ -71,11 +71,11 @@ def read_all_users(
|
|||
query: SelectOfScalar = select(User).offset(skip).limit(limit)
|
||||
users = session.exec(query).fetchall()
|
||||
|
||||
count_query = select(func.count()).select_from(User) # type: ignore
|
||||
count_query = select(func.count()).select_from(User)
|
||||
total_count = session.exec(count_query).first()
|
||||
|
||||
return UsersResponse(
|
||||
total_count=total_count, # type: ignore
|
||||
total_count=total_count,
|
||||
users=[UserRead(**user.model_dump()) for user in users],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class LCToolsAgentComponent(LCAgentComponent):
|
|||
runnable = agent
|
||||
else:
|
||||
runnable = AgentExecutor.from_agent_and_tools(
|
||||
agent=agent, # type: ignore
|
||||
agent=agent,
|
||||
tools=self.tools,
|
||||
handle_parsing_errors=self.handle_parsing_errors,
|
||||
verbose=self.verbose,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from collections.abc import Callable
|
||||
from typing import cast
|
||||
|
||||
from crewai import Agent, Crew, Process, Task # type: ignore
|
||||
from crewai.task import TaskOutput # type: ignore
|
||||
from crewai import Agent, Crew, Process, Task
|
||||
from crewai.task import TaskOutput
|
||||
from langchain_core.agents import AgentAction, AgentFinish
|
||||
|
||||
from langflow.custom import Component
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from crewai import Task # type: ignore
|
||||
from crewai import Task
|
||||
|
||||
|
||||
class SequentialTask(Task):
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ def retrieve_file_paths(
|
|||
|
||||
def partition_file_to_data(file_path: str, silent_errors: bool) -> Data | None:
|
||||
# Use the partition function to load the file
|
||||
from unstructured.partition.auto import partition # type: ignore
|
||||
from unstructured.partition.auto import partition
|
||||
|
||||
try:
|
||||
elements = partition(file_path)
|
||||
|
|
@ -108,14 +108,14 @@ def read_text_file(file_path: str) -> str:
|
|||
|
||||
|
||||
def read_docx_file(file_path: str) -> str:
|
||||
from docx import Document # type: ignore
|
||||
from docx import Document
|
||||
|
||||
doc = Document(file_path)
|
||||
return "\n\n".join([p.text for p in doc.paragraphs])
|
||||
|
||||
|
||||
def parse_pdf_to_text(file_path: str) -> str:
|
||||
from pypdf import PdfReader # type: ignore
|
||||
from pypdf import PdfReader
|
||||
|
||||
with Path(file_path).open("rb") as f:
|
||||
reader = PdfReader(f)
|
||||
|
|
|
|||
|
|
@ -97,4 +97,4 @@ class ChatComponent(Component):
|
|||
flow_id=self.graph.flow_id,
|
||||
)
|
||||
self.status = messages
|
||||
return message_text # type: ignore
|
||||
return message_text # type: ignore[return-value]
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ class LCModelComponent(Component):
|
|||
}
|
||||
}
|
||||
else:
|
||||
status_message = f"Response: {content}" # type: ignore
|
||||
status_message = f"Response: {content}" # type: ignore[assignment]
|
||||
else:
|
||||
status_message = f"Response: {message.content}" # type: ignore
|
||||
status_message = f"Response: {message.content}" # type: ignore[assignment]
|
||||
return status_message
|
||||
|
||||
def get_chat_result(
|
||||
|
|
@ -175,7 +175,7 @@ class LCModelComponent(Component):
|
|||
if self.output_parser is not None:
|
||||
runnable = runnable | self.output_parser
|
||||
|
||||
runnable = runnable.with_config( # type: ignore
|
||||
runnable = runnable.with_config(
|
||||
{
|
||||
"run_name": self.display_name,
|
||||
"project_name": self.get_project_name(),
|
||||
|
|
@ -183,8 +183,8 @@ class LCModelComponent(Component):
|
|||
}
|
||||
)
|
||||
if stream:
|
||||
return runnable.stream(inputs) # type: ignore
|
||||
message = runnable.invoke(inputs) # type: ignore
|
||||
return runnable.stream(inputs)
|
||||
message = runnable.invoke(inputs)
|
||||
result = message.content if hasattr(message, "content") else message
|
||||
if isinstance(message, AIMessage):
|
||||
status_message = self.build_status_message(message)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ def _format_tool_name(name: str):
|
|||
return re.sub(r"[^a-zA-Z0-9_-]", "-", name)
|
||||
|
||||
|
||||
class ComponentToolkit: # type: ignore
|
||||
class ComponentToolkit:
|
||||
def __init__(self, component: Component):
|
||||
self.component = component
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from crewai import Agent # type: ignore
|
||||
from crewai import Agent
|
||||
|
||||
from langflow.custom import Component
|
||||
from langflow.io import BoolInput, DictInput, HandleInput, MultilineInput, Output
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from crewai import Crew, Process # type: ignore
|
||||
from crewai import Crew, Process
|
||||
|
||||
from langflow.base.agents.crewai.crew import BaseCrewComponent
|
||||
from langflow.io import HandleInput
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from crewai import Agent, Crew, Process, Task # type: ignore
|
||||
from crewai import Agent, Crew, Process, Task
|
||||
|
||||
from langflow.base.agents.crewai.crew import BaseCrewComponent
|
||||
from langflow.io import HandleInput
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue