Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Add ruff rules for builtins (A) #4004

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/backend/base/langflow/base/tools/component_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from langflow.io import Output


def _get_input_type(input: InputTypes):
if input.input_types:
if len(input.input_types) == 1:
return input.input_types[0]
return " | ".join(input.input_types)
return input.field_type
def _get_input_type(_input: InputTypes):
if _input.input_types:
if len(_input.input_types) == 1:
return _input.input_types[0]
return " | ".join(_input.input_types)
return _input.field_type


def build_description(component: Component, output: Output):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ async def build_executor(self) -> Message:
self.status = status
return result_value

async def astream_events(self, input):
async for event in self.runnable.astream_events(input, version="v1"):
async def astream_events(self, runnable_input):
cbornet marked this conversation as resolved.
Show resolved Hide resolved
async for event in self.runnable.astream_events(runnable_input, version="v1"):
if event.get("event") != "on_chat_model_stream":
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def get_user_by_username(db: Session, username: str) -> User | None:
return db.exec(select(User).where(User.username == username)).first()


def get_user_by_id(db: Session, id: UUID) -> User | None:
return db.exec(select(User).where(User.id == id)).first()
def get_user_by_id(db: Session, user_id: UUID) -> User | None:
cbornet marked this conversation as resolved.
Show resolved Hide resolved
return db.exec(select(User).where(User.id == user_id)).first()


def update_user(user_db: User | None, user: UserUpdate, db: Session = Depends(get_session)) -> User:
Expand Down
8 changes: 4 additions & 4 deletions src/backend/base/langflow/services/telemetry/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.resources import Resource

# a default OpenTelelmetry meter name
# a default OpenTelemetry meter name
langflow_meter_name = "langflow"

"""
Expand Down Expand Up @@ -64,13 +64,13 @@ def __init__(
self,
name: str,
description: str,
type: MetricType,
metric_type: MetricType,
cbornet marked this conversation as resolved.
Show resolved Hide resolved
labels: dict[str, bool],
unit: str = "",
):
self.name = name
self.description = description
self.type = type
self.type = metric_type
self.unit = unit
self.labels = labels
self.mandatory_labels = [label for label, required in labels.items() if required]
Expand Down Expand Up @@ -114,7 +114,7 @@ class OpenTelemetry(metaclass=ThreadSafeSingletonMetaUsingWeakref):
_metrics_registry: dict[str, Metric] = {}

def _add_metric(self, name: str, description: str, unit: str, metric_type: MetricType, labels: dict[str, bool]):
metric = Metric(name=name, description=description, type=metric_type, unit=unit, labels=labels)
metric = Metric(name=name, description=description, metric_type=metric_type, unit=unit, labels=labels)
self._metrics_registry[name] = metric
if labels is None or len(labels) == 0:
msg = "Labels must be provided for the metric upon registration"
Expand Down
24 changes: 12 additions & 12 deletions src/backend/base/langflow/services/variable/kubernetes_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,31 @@ def encode_user_id(user_id: UUID | str) -> str:
return f"uuid-{str(user_id).lower()}"[:253]

# Convert string to lowercase
id = str(user_id).lower()
_user_id = str(user_id).lower()

# If the user_id looks like an email, replace @ and . with allowed characters
if "@" in id or "." in id:
id = id.replace("@", "-at-").replace(".", "-dot-")
if "@" in _user_id or "." in _user_id:
_user_id = _user_id.replace("@", "-at-").replace(".", "-dot-")

# Encode the user_id to base64
# encoded = base64.b64encode(user_id.encode("utf-8")).decode("utf-8")

# Replace characters not allowed in Kubernetes names
id = id.replace("+", "-").replace("/", "_").rstrip("=")
_user_id = _user_id.replace("+", "-").replace("/", "_").rstrip("=")

# Ensure the name starts with an alphanumeric character
if not id[0].isalnum():
id = "a-" + id
if not _user_id[0].isalnum():
_user_id = "a-" + _user_id

# Truncate to 253 characters (Kubernetes name length limit)
id = id[:253]
_user_id = _user_id[:253]

if not all(c.isalnum() or c in "-_" for c in id):
msg = f"Invalid user_id: {id}"
if not all(c.isalnum() or c in "-_" for c in _user_id):
msg = f"Invalid user_id: {_user_id}"
raise ValueError(msg)

# Ensure the name ends with an alphanumeric character
while not id[-1].isalnum():
id = id[:-1]
while not _user_id[-1].isalnum():
_user_id = _user_id[:-1]

return id
return _user_id
2 changes: 1 addition & 1 deletion src/backend/base/langflow/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_base_classes(cls):
bases = cls.__bases__
result = []
for base in bases:
if any(type in base.__module__ for type in ["pydantic", "abc"]):
if any(_type in base.__module__ for _type in ["pydantic", "abc"]):
continue
result.append(base.__name__)
base_classes = get_base_classes(base)
Expand Down
1 change: 1 addition & 0 deletions src/backend/base/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ flake8-bugbear.extend-immutable-calls = [
"typer.Option",
]
select = [
"A",
"ASYNC",
"B",
"C4",
Expand Down
Loading