-
Notifications
You must be signed in to change notification settings - Fork 6k
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 C416: unnecessary-comprehension #49852
Conversation
@MortalHappiness PTAL |
0635492
to
a79f6f5
Compare
@MortalHappiness PTAL |
Please resolve conflicting files. |
a79f6f5
to
6b565db
Compare
@@ -18,13 +18,13 @@ def __init__(self, grpc_context: grpc._cython.cygrpc._ServicerContext): | |||
self._auth_context = grpc_context.auth_context() | |||
self._code = grpc_context.code() | |||
self._details = grpc_context.details() | |||
self._invocation_metadata = [ | |||
self._invocation_metadata = [ # noqa: C416 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? invocation_metadata()
is not an iterator of tuples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just do: list(grpc_context.invocation_metadata)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my new commit that use list(grpc_context.invocation_metadata())
, but its CI failed.
0764a0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's the error: "Can't pickle <class 'importlib._bootstrap._Metadatum'>: attribute lookup _Metadatum on importlib._bootstrap failed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so somehow these two lines don't produce the same resulting list... amazing
i'm fine to just add the noqa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll reset to the version of using noqa
and rebase the master branch after work
6b565db
to
914eb64
Compare
Signed-off-by: Cheng-Yeh Chung <[email protected]>
Signed-off-by: Cheng-Yeh Chung <[email protected]>
Signed-off-by: Cheng-Yeh Chung <[email protected]>
Signed-off-by: Cheng-Yeh Chung <[email protected]>
914eb64
to
d361122
Compare
Why are these changes needed?
It's unnecessary to use a dict/list/set comprehension to build a data structure if the elements are unchanged. Wrap the iterable with dict(), list(), or set() instead.
Ref: https://docs.astral.sh/ruff/rules/unnecessary-comprehension/#unnecessary-comprehension-c416
Related issue number
#47991
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.