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

Issue detect useless generator pattern #520

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Karine-Bauch
Copy link

@Karine-Bauch Karine-Bauch commented Jul 21, 2023

In progress

@Karine-Bauch Karine-Bauch deleted the Issue-Detect-useless-generator-pattern branch July 22, 2023 09:33
@Karine-Bauch Karine-Bauch restored the Issue-Detect-useless-generator-pattern branch July 22, 2023 10:14
@Karine-Bauch Karine-Bauch reopened this Jul 22, 2023
@Karine-Bauch Karine-Bauch marked this pull request as draft July 22, 2023 10:18
@@ -199,6 +200,21 @@ def run(self) -> Generator[tuple[int, int, str, type[Any]], None, None]:
type(self),
)

elif (
node.func.id == "sorted"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the original issue:

the (a for a in b) generator construct doesn't seem particularly useful and just adds an unnecessary context switch of the generator.

I think we can check every generator, not only those inside sorted call.
This mean that the check would be only the isinstance of node as ast.GeneratorExp and isinstance of node.elt as ast.Name. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be right.
We should verify if the Generator do something, in all cases, not only for sorted call.
I need to put this on my desktop : KISS 👍

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

Successfully merging this pull request may close these issues.

None yet

2 participants