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

Is ruff unnecessary-map C417 actually equivalent to pylint use-a-generator R1729? #9500

Closed
dougthor42 opened this issue Jan 13, 2024 · 3 comments
Labels
question Asking for support or clarification

Comments

@dougthor42
Copy link
Contributor

Is ruff unnecessary-map C417 actually equivalent to pylint use-a-generator R1729?

In #970, use-a-generator is marked as complete via ruff rule C417 unnecessary-map.

The docs for pylint use-a-generator R1729 state:

Comprehension inside of 'any', 'all', 'max', 'min' or 'sum' is unnecessary. A generator would be sufficient and faster.

from random import randint

all([randint(-5, 5) > 0 for _ in range(10)])  # [use-a-generator]
any([randint(-5, 5) > 0 for _ in range(10)])  # [use-a-generator]

While the docs for ruff C417 unnecessary-map state:

Checks for unnecessary map calls with lambda functions.

  • Instead of list(map(lambda num: num * 2, nums)), use [num * 2 for num in nums].
  • Instead of set(map(lambda num: num % 2 == 0, nums)), use {num % 2 == 0 for num in nums}.
  • Instead of dict(map(lambda v: (v, v ** 2), values)), use {v: v ** 2 for v in values}.

Are they not actually equivalent? Or are docs incorrect?

If they're not equivalent, can the comment in #970 be updated?

I also found #3259 which appears to be related.

@charliermarsh
Copy link
Member

Oh, should it perhaps instead point to C419?

@charliermarsh charliermarsh added the question Asking for support or clarification label Jan 13, 2024
@dougthor42
Copy link
Contributor Author

Ah yes that looks like it, thanks! I think I couldn't find that because I was always searching for generator...

@charliermarsh
Copy link
Member

Fixed the reference in #970, thank you!

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

No branches or pull requests

2 participants