Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
refactor(git): code cleanup and test coverage #1417
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
base: master
Are you sure you want to change the base?
refactor(git): code cleanup and test coverage #1417
Changes from 1 commit
1cc5858
61c254f
40abbbd
20f4892
3962b80
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this less performant and harder to read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought evaluating
tag.strip()
twice is less performant? Not entirely sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these expressions are meant to process a string
c.out
by:Splitting it into lines.
Stripping each line.
Removing empty results.
They produce the same final list, but they differ in style, performance, and readability.
🔹 Version 1: List comprehension with
if
Strips each line.
Filters out empty strings after stripping.
Simple and readable.
Always creates a list.
🟢 Pros:
Clear, idiomatic Python.
Easy to read and debug.
🔴 Cons:
Slightly more verbose.
Calls
strip()
twice (once in result, once in filter).🔹 Version 2:
filter(None, ...)
with generator expressionUses
filter(None, ...)
to remove falsy values (like""
).Uses a generator expression, so it's more memory-efficient before converting to list.
Calls
strip()
only once per tag.🟢 Pros:
More efficient (calls
strip()
once).Shorter and elegant for experienced Python devs.
🔴 Cons:
Slightly less readable for beginners.
Using
filter(None, ...)
to drop empty values is more idiomatic than obvious.✅ Recommendation
If you're stripping expensive strings or the list is very large, prefer the second one.
You can also avoid double
strip()
in version 1 by assigning to a temporary:(Requires Python 3.8+ — uses the walrus operator
:=
.)Let me know if you want a performance comparison or an explanation of generator expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I use
[tag for raw in c.out.split("\n") if (tag := raw.strip())]
here, thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove the enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just found it hard to trace because it first converts a string to a enum and then converts it back to a string. I thought skipping the enum part may make more sense.
I added the enum back but reordered and rename the functions. Please review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't
elif
convey the meaning better? it's either this or that. Withif -> if
someone could introduce a refactor allowing you to fall into the nextif
which should not happenThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm
I prefer not to include an
else
clause after anif
block that concludes with areturn
, as it is typically unnecessary, right?