-
Notifications
You must be signed in to change notification settings - Fork 181
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
Replace format() function with f-strings on asv/console.py #1127
Replace format() function with f-strings on asv/console.py #1127
Conversation
This reverts commit 2af36bf.
…o airspeed-velocity-master
@datapythonista, this PR is ready for your review. Thanks a lot! |
asv/console.py
Outdated
@@ -218,8 +218,7 @@ def _stream_formatter(self, record): | |||
continued = getattr(record, 'continued', False) | |||
|
|||
if self._total: | |||
progress_msg = '[{0:6.02f}%] '.format( | |||
(float(self._count) / self._total) * 100.0) | |||
progress_msg = f'[{(float(self._count) / self._total) * 100.0:6.02f}%] ' |
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.
This is very difficult to read, you can define a variable instead.
asv/console.py
Outdated
progress_msg = '[{0:6.02f}%] '.format( | ||
(float(self._count) / self._total) * 100.0) | ||
percentage = (float(self._count) / self._total) * 100.0 | ||
progress_msg = f'[{percentage:6.02f}%] ' |
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.
The original code wasn't great. In Python you can actually do this:
>>> value = .2
>>> f'{value:.2%}'
'20.00%'
Also, converting self._count
to float
only made sense in Python 2, in Python 3 it's not needed. So, this could be something like (make sure we're not changing the result):
progress_msg = f'[{self._count / self._total:6.02%}] '
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! thanks for the suggestion :)
Thanks @LucyJimenez, nice clean up |
xref #1077
Change f-strings instead
.format()
onasv/console.py
.