ref: Add ruff rules for builtins (A) (#4004)
Add ruff rules for builtins (A)
This commit is contained in:
parent
528e676e56
commit
b591d7105e
7 changed files with 28 additions and 27 deletions
|
|
@ -17,12 +17,12 @@ if TYPE_CHECKING:
|
||||||
from langflow.io import Output
|
from langflow.io import Output
|
||||||
|
|
||||||
|
|
||||||
def _get_input_type(input: InputTypes):
|
def _get_input_type(_input: InputTypes):
|
||||||
if input.input_types:
|
if _input.input_types:
|
||||||
if len(input.input_types) == 1:
|
if len(_input.input_types) == 1:
|
||||||
return input.input_types[0]
|
return _input.input_types[0]
|
||||||
return " | ".join(input.input_types)
|
return " | ".join(_input.input_types)
|
||||||
return input.field_type
|
return _input.field_type
|
||||||
|
|
||||||
|
|
||||||
def build_description(component: Component, output: Output):
|
def build_description(component: Component, output: Output):
|
||||||
|
|
|
||||||
|
|
@ -130,8 +130,8 @@ class RunnableExecComponent(Component):
|
||||||
self.status = status
|
self.status = status
|
||||||
return result_value
|
return result_value
|
||||||
|
|
||||||
async def astream_events(self, input):
|
async def astream_events(self, runnable_input):
|
||||||
async for event in self.runnable.astream_events(input, version="v1"):
|
async for event in self.runnable.astream_events(runnable_input, version="v1"):
|
||||||
if event.get("event") != "on_chat_model_stream":
|
if event.get("event") != "on_chat_model_stream":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()
|
return db.exec(select(User).where(User.username == username)).first()
|
||||||
|
|
||||||
|
|
||||||
def get_user_by_id(db: Session, id: UUID) -> User | None:
|
def get_user_by_id(db: Session, user_id: UUID) -> User | None:
|
||||||
return db.exec(select(User).where(User.id == id)).first()
|
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:
|
def update_user(user_db: User | None, user: UserUpdate, db: Session = Depends(get_session)) -> User:
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ from opentelemetry.metrics._internal.instrument import Counter, Histogram, UpDow
|
||||||
from opentelemetry.sdk.metrics import MeterProvider
|
from opentelemetry.sdk.metrics import MeterProvider
|
||||||
from opentelemetry.sdk.resources import Resource
|
from opentelemetry.sdk.resources import Resource
|
||||||
|
|
||||||
# a default OpenTelelmetry meter name
|
# a default OpenTelemetry meter name
|
||||||
langflow_meter_name = "langflow"
|
langflow_meter_name = "langflow"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -64,13 +64,13 @@ class Metric:
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
description: str,
|
description: str,
|
||||||
type: MetricType,
|
metric_type: MetricType,
|
||||||
labels: dict[str, bool],
|
labels: dict[str, bool],
|
||||||
unit: str = "",
|
unit: str = "",
|
||||||
):
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
self.type = type
|
self.type = metric_type
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
self.labels = labels
|
self.labels = labels
|
||||||
self.mandatory_labels = [label for label, required in labels.items() if required]
|
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] = {}
|
_metrics_registry: dict[str, Metric] = {}
|
||||||
|
|
||||||
def _add_metric(self, name: str, description: str, unit: str, metric_type: MetricType, labels: dict[str, bool]):
|
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
|
self._metrics_registry[name] = metric
|
||||||
if labels is None or len(labels) == 0:
|
if labels is None or len(labels) == 0:
|
||||||
msg = "Labels must be provided for the metric upon registration"
|
msg = "Labels must be provided for the metric upon registration"
|
||||||
|
|
|
||||||
|
|
@ -164,31 +164,31 @@ def encode_user_id(user_id: UUID | str) -> str:
|
||||||
return f"uuid-{str(user_id).lower()}"[:253]
|
return f"uuid-{str(user_id).lower()}"[:253]
|
||||||
|
|
||||||
# Convert string to lowercase
|
# 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 the user_id looks like an email, replace @ and . with allowed characters
|
||||||
if "@" in id or "." in id:
|
if "@" in _user_id or "." in _user_id:
|
||||||
id = id.replace("@", "-at-").replace(".", "-dot-")
|
_user_id = _user_id.replace("@", "-at-").replace(".", "-dot-")
|
||||||
|
|
||||||
# Encode the user_id to base64
|
# Encode the user_id to base64
|
||||||
# encoded = base64.b64encode(user_id.encode("utf-8")).decode("utf-8")
|
# encoded = base64.b64encode(user_id.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
# Replace characters not allowed in Kubernetes names
|
# 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
|
# Ensure the name starts with an alphanumeric character
|
||||||
if not id[0].isalnum():
|
if not _user_id[0].isalnum():
|
||||||
id = "a-" + id
|
_user_id = "a-" + _user_id
|
||||||
|
|
||||||
# Truncate to 253 characters (Kubernetes name length limit)
|
# 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):
|
if not all(c.isalnum() or c in "-_" for c in _user_id):
|
||||||
msg = f"Invalid user_id: {id}"
|
msg = f"Invalid user_id: {_user_id}"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
# Ensure the name ends with an alphanumeric character
|
# Ensure the name ends with an alphanumeric character
|
||||||
while not id[-1].isalnum():
|
while not _user_id[-1].isalnum():
|
||||||
id = id[:-1]
|
_user_id = _user_id[:-1]
|
||||||
|
|
||||||
return id
|
return _user_id
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ def get_base_classes(cls):
|
||||||
bases = cls.__bases__
|
bases = cls.__bases__
|
||||||
result = []
|
result = []
|
||||||
for base in bases:
|
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
|
continue
|
||||||
result.append(base.__name__)
|
result.append(base.__name__)
|
||||||
base_classes = get_base_classes(base)
|
base_classes = get_base_classes(base)
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,7 @@ flake8-bugbear.extend-immutable-calls = [
|
||||||
"typer.Option",
|
"typer.Option",
|
||||||
]
|
]
|
||||||
select = [
|
select = [
|
||||||
|
"A",
|
||||||
"ASYNC",
|
"ASYNC",
|
||||||
"B",
|
"B",
|
||||||
"C4",
|
"C4",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue