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

Strange behavior with multi-nested for loops with "Replaces a nested for loop with a call to itertools.product" solution #214

Closed
diceroll123 opened this issue Mar 28, 2022 · 3 comments
Labels
bug Something isn't working next release This will be fixed in next release

Comments

@diceroll123
Copy link

diceroll123 commented Mar 28, 2022

Issue description or question

I don't consider this to be high priority, but a couple things could be improved on this sourcery solution.

Consider this code:

for _a in range(5):
    for _b in range(5):
        for _c in range(5):
            for _d in range(5):
                for _e in range(5):
                    ...

Sourcery turns it into:

import itertools

for (_a, _b), _c, _d, _e in itertools.product(itertools.product(range(5), range(5)), range(5), range(5), range(5)):
    ...

...which is close to what I expected, and it works fine, but if you look carefully, it used itertools.product twice, and grouped _a and _b together for the inner product call.

That's extraneous, as:

for _a, _b, _c, _d, _e in itertools.product(range(5), range(5), range(5), range(5), range(5)):
    ...

Is the simplified version.

Although

Matching this specific format, it could be improved further to look like:

for _a, _b, _c, _d, _e in itertools.product(range(5), repeat=5):
    ...

Hope this helps!

Sourcery Version

0.11.1

Code editor or IDE name and version

Version: 1.65.2 (user setup)
Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
Date: 2022-03-10T14:33:55.248Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.22581

@brendanator
Copy link
Collaborator

Thanks for raising this @diceroll123!

I can reproduce and will investigate

@brendanator brendanator added the bug Something isn't working label Mar 28, 2022
@brendanator
Copy link
Collaborator

This has been investigated by @bm424 and will be fixed in the next release

@brendanator brendanator added the next release This will be fixed in next release label Apr 4, 2022
@Hellebore
Copy link
Collaborator

Resolved with release of 0.11.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release This will be fixed in next release
Projects
None yet
Development

No branches or pull requests

3 participants