Sourcery Starbot ⭐ refactored wolph/python-progressbar#279
Sourcery Starbot ⭐ refactored wolph/python-progressbar#279SourceryAI wants to merge 1 commit into
Conversation
SourceryAI
left a comment
There was a problem hiding this comment.
Due to GitHub API limits, only the first 60 comments can be shown.
| @example | ||
| def shortcut_example(): | ||
| for i in progressbar.progressbar(range(10)): | ||
| for _ in progressbar.progressbar(range(10)): |
There was a problem hiding this comment.
Function shortcut_example refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| @example | ||
| def prefixed_shortcut_example(): | ||
| for i in progressbar.progressbar(range(10), prefix='Hi: '): | ||
| for _ in progressbar.progressbar(range(10), prefix='Hi: '): |
There was a problem hiding this comment.
Function prefixed_shortcut_example refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| @example | ||
| def templated_shortcut_example(): | ||
| for i in progressbar.progressbar(range(10), suffix='{seconds_elapsed:.1}'): | ||
| for _ in progressbar.progressbar(range(10), suffix='{seconds_elapsed:.1}'): |
There was a problem hiding this comment.
Function templated_shortcut_example refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| jobs = [ | ||
| # Each job takes between 1 and 10 steps to complete | ||
| [0, random.randint(1, 10)] | ||
| for i in range(25) # 25 jobs total | ||
| ] | ||
| jobs = [[0, random.randint(1, 10)] for _ in range(25)] | ||
|
|
||
| widgets = [ | ||
| progressbar.Percentage(), | ||
| ' ', progressbar.MultiProgressBar('jobs', fill_left=left), | ||
| ] | ||
|
|
||
| max_value = sum([total for progress, total in jobs]) | ||
| max_value = sum(total for progress, total in jobs) |
There was a problem hiding this comment.
Function multi_progress_bar_example refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Replace unneeded comprehension with generator [×2] (
comprehension-to-generator)
This removes the following comments ( why? ):
# Each job takes between 1 and 10 steps to complete
# 25 jobs total
| for i in progressbar.progressbar(list(range(100)), widgets=widgets): | ||
| for _ in progressbar.progressbar(list(range(100)), widgets=widgets): | ||
| time.sleep(0.03) | ||
|
|
||
| for i in progressbar.progressbar(iter(range(100)), widgets=widgets): | ||
| for _ in progressbar.progressbar(iter(range(100)), widgets=widgets): |
There was a problem hiding this comment.
Function granular_progress_example refactored with the following changes:
- Replace unused for index with underscore [×2] (
for-index-underscore)
| for i in bar((i for i in range(24))): | ||
| for _ in bar(iter(range(24))): |
There was a problem hiding this comment.
Function animated_wheels refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in bar((i for i in range(100))): | ||
| for _ in bar(iter(range(100))): |
There was a problem hiding this comment.
Function format_label_bouncer refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in bar((i for i in range(18))): | ||
| for _ in bar(iter(range(18))): |
There was a problem hiding this comment.
Function format_label_rotating_bouncer refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in range(10): | ||
| for _ in range(10): |
There was a problem hiding this comment.
Function incrementing_bar refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for i in range(100): | ||
| for _ in range(100): |
There was a problem hiding this comment.
Function adaptive_eta_without_value_change refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for n in bar(iter(range(100)), 100): | ||
| for _ in bar(iter(range(100)), 100): |
There was a problem hiding this comment.
Function iterator_with_max_value refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| prefix='{variables.task} >> {variables.subtask}', | ||
| variables={'task': '--', 'subtask': '--'}, | ||
| max_value=10 * num_subtasks) as bar: | ||
| prefix='{variables.task} >> {variables.subtask}', | ||
| variables={'task': '--', 'subtask': '--'}, | ||
| max_value=10 * num_subtasks) as bar: | ||
| for tasks_name, subtasks in tasks.items(): | ||
| for subtask_name in subtasks: | ||
| for i in range(10): | ||
| for _ in range(10): |
There was a problem hiding this comment.
Function user_variables refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for i in bar(range(200)): | ||
| for _ in bar(range(200)): |
There was a problem hiding this comment.
Function simple_api_example refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| if sys.argv[-1] == 'info': | ||
| for k, v in about.items(): | ||
| print('%s: %s' % (k, v)) | ||
| print(f'{k}: {v}') |
There was a problem hiding this comment.
Lines 19-19 refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 'vt(10[02]|220|320)', | ||
| ) | ||
| ANSI_TERM_RE = re.compile('^({})'.format('|'.join(ANSI_TERMS)), re.IGNORECASE) | ||
| ANSI_TERM_RE = re.compile(f"^({'|'.join(ANSI_TERMS)})", re.IGNORECASE) |
There was a problem hiding this comment.
Lines 42-42 refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| def _flush(self) -> None: | ||
| value = self.buffer.getvalue() | ||
| if value: | ||
| if value := self.buffer.getvalue(): |
There was a problem hiding this comment.
Function WrappingIO._flush refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| if self.wrapped_stdout: # pragma: no branch | ||
| if isinstance(self.stdout, WrappingIO): # pragma: no branch | ||
| try: | ||
| self.stdout._flush() | ||
| except io.UnsupportedOperation: # pragma: no cover | ||
| self.wrapped_stdout = False | ||
| logger.warning( | ||
| 'Disabling stdout redirection, %r is not seekable', | ||
| sys.stdout, | ||
| ) | ||
|
|
||
| if self.wrapped_stderr: # pragma: no branch | ||
| if isinstance(self.stderr, WrappingIO): # pragma: no branch | ||
| try: | ||
| self.stderr._flush() | ||
| except io.UnsupportedOperation: # pragma: no cover | ||
| self.wrapped_stderr = False | ||
| logger.warning( | ||
| 'Disabling stderr redirection, %r is not seekable', | ||
| sys.stderr, | ||
| ) | ||
| if self.wrapped_stdout and isinstance(self.stdout, WrappingIO): | ||
| try: | ||
| self.stdout._flush() | ||
| except io.UnsupportedOperation: # pragma: no cover | ||
| self.wrapped_stdout = False | ||
| logger.warning( | ||
| 'Disabling stdout redirection, %r is not seekable', | ||
| sys.stdout, | ||
| ) | ||
|
|
||
| if self.wrapped_stderr and isinstance(self.stderr, WrappingIO): | ||
| try: | ||
| self.stderr._flush() | ||
| except io.UnsupportedOperation: # pragma: no cover | ||
| self.wrapped_stderr = False | ||
| logger.warning( | ||
| 'Disabling stderr redirection, %r is not seekable', | ||
| sys.stderr, | ||
| ) |
There was a problem hiding this comment.
Function StreamWrapper.flush refactored with the following changes:
- Merge nested if conditions [×2] (
merge-nested-ifs)
This removes the following comments ( why? ):
# pragma: no branch
| raise AttributeError("No such attribute: " + name) | ||
| raise AttributeError(f"No such attribute: {name}") |
There was a problem hiding this comment.
Function AttributeDict.__getattr__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| raise AttributeError("No such attribute: " + name) | ||
| raise AttributeError(f"No such attribute: {name}") |
There was a problem hiding this comment.
Function AttributeDict.__delattr__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return format.format(**data) | ||
| else: | ||
| return format % data | ||
| return format.format(**data) if self.new_style else format % data |
There was a problem hiding this comment.
Function FormatWidgetMixin.__call__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| for key, value in self._fixed_colors.items(): | ||
| if value is not None: | ||
| return True | ||
|
|
||
| return False | ||
| return any(value is not None for key, value in self._fixed_colors.items()) |
There was a problem hiding this comment.
Function WidgetBase.uses_colors refactored with the following changes:
- Use any() instead of for loop (
use-any)
| if transform is None: | ||
| data[name] = data[key] | ||
| else: | ||
| data[name] = transform(data[key]) | ||
| data[name] = data[key] if transform is None else transform(data[key]) |
There was a problem hiding this comment.
Function FormatLabel.__call__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| return progress.extra.setdefault(self.key_prefix + 'sample_times', []) | ||
| return progress.extra.setdefault(f'{self.key_prefix}sample_times', []) |
There was a problem hiding this comment.
Function SamplesMixin.get_sample_times refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return progress.extra.setdefault(self.key_prefix + 'sample_values', []) | ||
| return progress.extra.setdefault(f'{self.key_prefix}sample_values', []) |
There was a problem hiding this comment.
Function SamplesMixin.get_sample_values refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| for i in pbar(range(80)): | ||
| for _ in pbar(range(80)): |
There was a problem hiding this comment.
Function example7 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for i in pbar((i for i in range(80))): | ||
| for _ in pbar(iter(range(80))): |
There was a problem hiding this comment.
Function example8 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in pbar((i for i in range(50))): | ||
| for _ in pbar(iter(range(50))): |
There was a problem hiding this comment.
Function example9 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in pbar((i for i in range(150))): | ||
| for _ in pbar(iter(range(150))): |
There was a problem hiding this comment.
Function example10 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
| for i in pbar((i for i in range(150))): | ||
| for _ in pbar(iter(range(150))): |
There was a problem hiding this comment.
Function example11 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Simplify generator expression (
simplify-generator)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
developbranch, then run: