-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Join strings instead of adding them. #10332
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
Conversation
That is exciting that we do not run any of those lines of code in the test suite! |
writeln(self.fh, | ||
r"\pgfsetdash{" | ||
+ "".join(r"{%fpt}" % dash for dash in dash_list) | ||
+ "r}{%fpt}" % dash_offset) |
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.
588: "r
: The r was a raw string qualifier before and seems to have slipped into the string.
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.
cf @tacaswell's comment about none of this being tested :p
fixed
dash_str += r"{%fpt}" % dash | ||
dash_str += r"}{%fpt}" % dash_offset | ||
writeln(self.fh, dash_str) | ||
writeln(self.fh, |
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.
On the danger of being pedantic, I would simply write
dash_pattern = "".join(r"{%fpt}" % dash for dash in dash_list)
writeln(self.fh,
r"\pgfsetdash{%s}{%fpt}" % (dash_pattern, dash_offset))
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.
done
See e.g. https://docs.python.org/3/library/functions.html#sum that documents "".join as the preferred method (briefly, because summing (or repeated addition) has quadratic complexity for strings).
See e.g. https://docs.python.org/3/library/functions.html#sum that
documents "".join as the preferred method (briefly, because summing (or
repeated addition) has quadratic complexity for strings).
side note:
https://github.com/takluyver/astsearch and https://github.com/hchasestevens/astpath are quite nice for this kind of cleanups...
PR Summary
PR Checklist