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

Add ruff rules for builtins (A)
This commit is contained in:
Christophe Bornet 2024-10-03 16:26:27 +02:00 committed by GitHub
commit b591d7105e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 additions and 27 deletions

View file

@ -17,12 +17,12 @@ if TYPE_CHECKING:
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):

View file

@ -130,8 +130,8 @@ class RunnableExecComponent(Component):
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):
async for event in self.runnable.astream_events(runnable_input, version="v1"):
if event.get("event") != "on_chat_model_stream":
continue

View file

@ -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:
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:

View file

@ -12,7 +12,7 @@ from opentelemetry.metrics._internal.instrument import Counter, Histogram, UpDow
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"
"""
@ -64,13 +64,13 @@ class Metric:
self,
name: str,
description: str,
type: MetricType,
metric_type: MetricType,
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]
@ -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"

View file

@ -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

View file

@ -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)

View file

@ -157,6 +157,7 @@ flake8-bugbear.extend-immutable-calls = [
"typer.Option",
]
select = [
"A",
"ASYNC",
"B",
"C4",