[CodeStyle][C403][C404] Replace unnecessary-list-comprehension-set/dict #51964
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Others
PR changes
Others
Describe
According to https://pypi.org/project/flake8-comprehensions/
C403-404: Unnecessary list comprehension - rewrite as a <set/dict> comprehension.
Rules:
C403 Unnecessary list comprehension - rewrite as a set comprehension.
C404 Unnecessary list comprehension - rewrite as a dict comprehension.
It’s unnecessary to use a list comprehension inside a call to set or dict, since there are equivalent comprehensions for these types. For example:
Rewrite set([f(x) for x in foo]) as {f(x) for x in foo}
Rewrite dict([(x, f(x)) for x in foo]) as {x: f(x) for x in foo}
but in python/paddle/fluid/tests/unittests/test_dist_lookup_sparse_table_fuse_ops.py
scope.var("Ids").get_tensor().set([i for i in range(100)], place) can't replace to
scope.var("Ids").get_tensor().{i for i in range(100)], place} or
scope.var("Ids").get_tensor().{place for place in range(100)}
so I think C403 can't using it.
but C404 can use it.