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

[Enhancement]: defaulted next to except StopIteration #342

Open
jamesbraza opened this issue Jun 22, 2024 · 1 comment
Open

[Enhancement]: defaulted next to except StopIteration #342

jamesbraza opened this issue Jun 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jamesbraza
Copy link

Overview

Firstly, hope all is well! I have successfully adopted refurb>=2 and it's working great. So excellent work with the v2 major bump.


I would like to request a new rule: reporting to go from defaulted next to except StopIteration. Please see the below Proposal.

Proposal

list_of_truthy = [False, False]

# Slightly suboptimal route 1: passing default of None
first_truthy = next((t for t in list_of_truthy if t), None)
if first_truthy is None:
    raise ValueError(f"{list_of_truthy} has no truthy items.")

# More optimal route 2: try-except
try:
    first_truthy = next(t for t in list_of_truthy if t)
except StopIteration as exc:
    raise ValueError(f"{list_of_truthy} has no truthy items.") from exc
@jamesbraza jamesbraza added the enhancement New feature or request label Jun 22, 2024
@dosisod
Copy link
Owner

dosisod commented Nov 21, 2024

@jamesbraza Thank you for the kind words! I'm responding to this late so v2 feels like it was ages ago, but it was a huge milestone, I'm glad to be working on this project a bit more now.

This would be a good feature to add, and AFAICT, it isn't implemented in Ruff, so this would be a good candidate.

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

No branches or pull requests

2 participants