-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
FURB148 generates invalid fix when arg is a generator #7656
Comments
Thanks! |
This will probably require type inference as the variable might be defined outside the |
@dhruvmanila True, but in the meantime we shouldn't suggest or force the change because if the arg is a generator, enumerate might strictly be better than range (I can't think of a cleaner way to do it). |
Suppressing the fix would still have the rule trigger, which is less destructive but still frustrating for the user who has to figure out it's a false negative and suppress the rule. Limiting the rule to known safe sequences (for example, using |
Yeah, I think my suggestion would be to only trigger the enumerate case if |
Feel free to assign to me, I can work on a merge request tomorrow. |
gets autofixed to:
but a is a generator, and
len
, surprisingly cannot take a generator (len needs a SizedSequence). Running the code in this autofix will generate the following error:So while this would work if object was a SizedSequence like a tuple, list, dict, or set, it does not work in this case and will generate invalid.
As an aside, using enumerate to generate an index here when it's a generator is rather nifty, not sure there is an easier way to actually get a range length on generator, using enumerate might actually be most efficient in this case.
The command run is
ruff test_file.py --select FURB148 --preview --fix
on
ruff 0.0.291
The text was updated successfully, but these errors were encountered: