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

style: flake8 violation F401 #48185

Closed
wants to merge 2 commits into from

Conversation

fscnick
Copy link
Contributor

@fscnick fscnick commented Oct 22, 2024

Why are these changes needed?

While running the pre-commit hook of flake8, the following error occurs if Python version is 3.12. It's because the version of flake8 is too old.

./python/ray/experimental/channel/nccl_group.py:13:5: F401 'cupy as cp' imported but unused
./python/ray/tests/autoscaler_test_utils.py:5:1: F401 'typing.Callable' imported but unused
./rllib/evaluation/sampler.py:58:5: F401 'gymnasium.envs.classic_control.rendering.SimpleImageViewer' imported but unused

However, there are another violation appeared after removing these unused import.

python/ray/experimental/channel/nccl_group.py:91:37: F821 undefined name 'cp'
python/ray/tests/autoscaler_test_utils.py:46:55: F821 undefined name 'Callable'
rllib/evaluation/sampler.py:343:35: F821 undefined name 'SimpleImageViewer'

After taking a look,
nccl_group.py:91 and sampler.py:58 are used in Optional
autoscaler_test_utils.py:46 Callable is used in type comment.

Thus, suppress F401.

Related issue number

Closes #48062

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

@fscnick
Copy link
Contributor Author

fscnick commented Oct 22, 2024

@MortalHappiness PTAL

@@ -43,7 +43,7 @@ def matches(self, tags):
class MockProcessRunner:
def __init__(self, fail_cmds=None, cmd_to_callback=None, print_out=False):
self.calls = []
self.cmd_to_callback = cmd_to_callback or {} # type: Dict[str, Callable]
self.cmd_to_callback: Dict[str, Callable] = cmd_to_callback or {}
Copy link

@Daraan Daraan Oct 24, 2024

Choose a reason for hiding this comment

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

Disclaimer: I am just some random person showing up here.

As the minimum version is now 3.9 and PEP 585 is available. typing.Dict, typing.Callable and similar are deprecated.

Now we can (and should rather) use from collections.abc import Callable and the builtins dict instead, if we do not care about backward compatibility

Suggested change
self.cmd_to_callback: Dict[str, Callable] = cmd_to_callback or {}
self.cmd_to_callback: dict[str, Callable] = cmd_to_callback or {}

Copy link
Member

Choose a reason for hiding this comment

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

You're right. However, since our Python worker in CI is still on Python 3.8, we cannot change this now. I'm still waiting for our CI team to upgrade the worker to Python 3.9. Additionally, many places still use typing.Dict as a type annotation. We can use tools to update it to the new syntax after the Python worker version is upgraded.

@MortalHappiness
Copy link
Member

Close this because we decide to migrate from flake8 to ruff instead of upgrading flake8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flake8 rule F401: Module imported but unused
3 participants