Sourcery Starbot ⭐ refactored leika/USB_Deck#1
Sourcery Starbot ⭐ refactored leika/USB_Deck#1SourceryAI wants to merge 1 commit intoleika:masterfrom
Conversation
| try: | ||
| if package: | ||
| p = __import__(package + ".R", None, None, True) | ||
| p = __import__(f"{package}.R", None, None, True) |
There was a problem hiding this comment.
Function resource_stream refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| if l is not None: | ||
| return l | ||
| return "LVL%s" % level | ||
| return l if l is not None else f"LVL{level}" |
There was a problem hiding this comment.
Function Logger._level_str refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| _stream.write("%s:%s:" % (self._level_str(level), self.name)) | ||
| _stream.write(f"{self._level_str(level)}:{self.name}:") |
There was a problem hiding this comment.
Function Logger.log refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| l = f.readinto(buf) | ||
| if not l: | ||
| if l := f.readinto(buf): | ||
| yield from writer.awrite(buf, 0, l) | ||
| else: | ||
| break | ||
| yield from writer.awrite(buf, 0, l) |
There was a problem hiding this comment.
Function sendstream refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Swap if/else branches (
swap-if-else-branches)
| return | ||
| yield from writer.awrite("\r\n") | ||
| if isinstance(headers, bytes) or isinstance(headers, str): | ||
| if isinstance(headers, (bytes, str)): |
There was a problem hiding this comment.
Function start_response refactored with the following changes:
- Merge isinstance calls (
merge-isinstance)
| def render_expr(self, e): | ||
| self.indent() | ||
| self.file_out.write('yield str(' + e + ')\n') | ||
| self.file_out.write(f'yield str({e}' + ')\n') |
There was a problem hiding this comment.
Function Compiler.render_expr refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| self.args = tokens[1] | ||
| else: | ||
| self.args = "" | ||
| self.args = tokens[1] if len(tokens) > 1 else "" |
There was a problem hiding this comment.
Function Compiler.parse_statement refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Replace if statement with if expression [×2] (
assign-if-exp) - Move setting of default value for variable into
elsebranch (introduce-default-else)
| if isinstance(p.__path__, str): | ||
| # uPy | ||
| self.pkg_path = p.__path__ | ||
| else: | ||
| # CPy | ||
| self.pkg_path = p.__path__[0] | ||
| self.pkg_path = p.__path__ if isinstance(p.__path__, str) else p.__path__[0] |
There was a problem hiding this comment.
Function Loader.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# CPy
# uPy
| return self.dir + "/" + template.replace(".", "_") + ".py" | ||
| return f"{self.dir}/" + template.replace(".", "_") + ".py" |
There was a problem hiding this comment.
Function Loader.compiled_path refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| f_out = open(compiled_path, "w") | ||
| c = Compiler(f_in, f_out, loader=self) | ||
| c.compile() | ||
| f_in.close() | ||
| f_out.close() | ||
| with open(compiled_path, "w") as f_out: | ||
| c = Compiler(f_in, f_out, loader=self) | ||
| c.compile() | ||
| f_in.close() |
There was a problem hiding this comment.
Function Loader.load refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
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
masterbranch, then run: