chore(python): bump ruff to 0.15.12 and apply format#2145
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the ruff linter to version 0.15.12 and includes widespread reformatting of assert statements across the codebase, likely triggered by the linter update. Feedback focuses on the use of assert for runtime validation in production logic; it is recommended to replace these with explicit exceptions like RuntimeError or ValueError to prevent them from being optimized away in production environments.
| assert self.driver is not None, ( | ||
| "Driver must be initialized before executing jobs" | ||
| ) |
There was a problem hiding this comment.
Using assert for runtime state validation in production code is discouraged because assertions can be disabled globally in Python (using the -O flag). If self.driver is None, it is better to raise an explicit exception like RuntimeError to ensure the check is always performed and provides a clear error message.
if self.driver is None:
raise RuntimeError("Driver must be initialized before executing jobs")| assert self.driver is not None, ( | ||
| "Driver must be initialized before waiting for jobs" | ||
| ) |
There was a problem hiding this comment.
Using assert for runtime state validation in production code is discouraged because assertions can be disabled globally in Python (using the -O flag). If self.driver is None, it is better to raise an explicit exception like RuntimeError to ensure the check is always performed and provides a clear error message.
if self.driver is None:
raise RuntimeError("Driver must be initialized before waiting for jobs")| assert self.health_checker is not None, ( | ||
| "Health checker should be initialized" | ||
| ) |
There was a problem hiding this comment.
Using assert for runtime state validation in production code is discouraged because assertions can be disabled globally in Python (using the -O flag). If self.health_checker is None, it is better to raise an explicit exception like RuntimeError to ensure the check is always performed and provides a clear error message.
if self.health_checker is None:
raise RuntimeError("Health checker should be initialized")| assert job_status.in_progress_at is not None, ( | ||
| "AssertError: Job must be set as in progress before setting as ready" | ||
| ) |
There was a problem hiding this comment.
Using assert for state validation in production logic is risky because it can be optimized away. Consider raising a ValueError or a custom exception instead to ensure the check is always executed.
if job_status.in_progress_at is None:
raise ValueError("Job must be set as in progress before setting as ready")| assert metric.name == self.original_name, ( | ||
| f"Metric name {metric.name} does not match Rule original name {self.original_name}" | ||
| ) |
There was a problem hiding this comment.
Using assert for validating input parameters or state in production code is not recommended. If the condition fails, it is better to raise a ValueError with a descriptive message to ensure the error is caught even in optimized environments.
| assert metric.name == self.original_name, ( | |
| f"Metric name {metric.name} does not match Rule original name {self.original_name}" | |
| ) | |
| if metric.name != self.original_name: | |
| raise ValueError( | |
| f"Metric name {metric.name} does not match Rule original name {self.original_name}" | |
| ) |
| assert metric.name == self.metric_name, ( | ||
| f"Metric name {metric.name} does not match Rule metric name {self.metric_name}" | ||
| ) |
There was a problem hiding this comment.
Using assert for validating input parameters or state in production code is not recommended. If the condition fails, it is better to raise a ValueError with a descriptive message to ensure the error is caught even in optimized environments.
| assert metric.name == self.metric_name, ( | |
| f"Metric name {metric.name} does not match Rule metric name {self.metric_name}" | |
| ) | |
| if metric.name != self.metric_name: | |
| raise ValueError( | |
| f"Metric name {metric.name} does not match Rule metric name {self.metric_name}" | |
| ) |
|
can you sign the PR. |
Jeffwan
left a comment
There was a problem hiding this comment.
overall looks good to me. we make lots of changes to poetry recently, please rebase the master to fetch the latest code
|
@mvanhorn could you help regenerate the lock file using higher poetry version |
Closes #2143.
Bumps
rufffrom0.6.1(mid 2024) to0.15.12(latest) and appliesruff formatso the formatter check is in sync with the new version.Changes
python/aibrix/pyproject.toml:ruff = "0.6.1"->ruff = "0.15.12".python/aibrix/poetry.lock: regenerated to lock ruff at0.15.12. Generated with poetry1.8.5(lockfile header). The non-ruff diff is two reordered marker lists (uvloop, pandasnumpy) — the resolved versions are identical.ruff format. Each file is the exact set listed in the issue body. Diffs are formatter-only —ast.parseconfirms identical ASTs before and after.Verification
From
python/aibrix/:Both gates from
.github/workflows/python-aibrix-tests.ymlpass cleanly with the new pin.