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

[Refactor] Fix ruff rule B018: useless-expression #50010

Merged
merged 3 commits into from
Jan 26, 2025

Conversation

win5923
Copy link
Contributor

@win5923 win5923 commented Jan 22, 2025

Why are these changes needed?

Useless expressions have no effect on the program, and are often included by mistake. Assign a useless expression to a variable, or remove it entirely.

However, if a seemingly useless expression (like an attribute access) is needed to trigger a side effect, consider assigning it to an anonymous variable, to indicate that the return value is intentionally ignored.

Ref: https://docs.astral.sh/ruff/rules/useless-expression/

Related issue number

#47991

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@win5923 win5923 force-pushed the ruff/B018 branch 2 times, most recently from 19c83d3 to 88955f1 Compare January 22, 2025 16:38
@jcotant1 jcotant1 added the core Issues that should be addressed in Ray Core label Jan 23, 2025
Signed-off-by: win5923 <[email protected]>
@@ -4,7 +4,7 @@
@serve.deployment
class A:
def __init__(self):
1 / 0
raise ZeroDivisionError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also change this and the other places to _ = 1 / 0

python/ray/serve/tests/test_metrics.py Outdated Show resolved Hide resolved
python/ray/train/tests/test_base_trainer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hongpeng-guo hongpeng-guo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: win5923 <[email protected]>
@win5923 win5923 requested a review from aslonnie January 24, 2025 06:02
@aslonnie aslonnie added the go add ONLY when ready to merge, run all tests label Jan 24, 2025
@aslonnie aslonnie merged commit 5d69930 into ray-project:master Jan 26, 2025
6 checks passed
@win5923 win5923 deleted the ruff/B018 branch January 27, 2025 03:45
srinathk10 pushed a commit that referenced this pull request Feb 2, 2025
Useless expressions have no effect on the program, and are often included by mistake. Assign a useless expression to a variable, or remove it entirely.

However, if a seemingly useless expression (like an attribute access) is needed to trigger a side effect, consider assigning it to an anonymous variable, to indicate that the return value is intentionally ignored.

---------

Signed-off-by: win5923 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants