-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
if ("a" + s).isidentifier() and not re.match(r"\w", s): | ||
if f"a{s}".isidentifier() and not re.match(r"\w", s): |
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.
Function get_characters
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
out.append(a) | ||
out.append(b) | ||
out.extend((a, b)) |
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.
Function build_pattern
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
if b: | ||
return async_func(*args, **kwargs) | ||
|
||
return normal_func(*args, **kwargs) | ||
return async_func(*args, **kwargs) if b else normal_func(*args, **kwargs) |
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.
Function async_variant
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
)
self.write("(" + op) | ||
self.write(f"({op}") |
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.
Function _make_unop
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if stream is None: | ||
return generator.stream.getvalue() # type: ignore | ||
|
||
return None | ||
return generator.stream.getvalue() if stream is None else None |
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.
Function generate
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
)
This removes the following comments ( why? ):
# type: ignore
if type(cache) is dict: | ||
return {} | ||
|
||
return LRUCache(cache.capacity) # type: ignore | ||
return {} if type(cache) is dict else LRUCache(cache.capacity) |
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.
Function copy_cache
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
)
This removes the following comments ( why? ):
# type: ignore
if context is not None: | ||
eval_ctx = context.eval_ctx | ||
else: | ||
eval_ctx = EvalContext(self) | ||
|
||
eval_ctx = context.eval_ctx if context is not None else EvalContext(self) |
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.
Function Environment._filter_test_common
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
source = str(source) | ||
source = source |
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.
Function Environment.lex
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
str(source), | ||
source, |
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.
Function Environment.preprocess
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
keys = ctx.globals_keys - self.globals.keys() | ||
|
||
if keys: | ||
if keys := ctx.globals_keys - self.globals.keys(): |
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.
Function Template._get_default_module
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
keys = ctx.globals_keys - self.globals.keys() | ||
|
||
if keys: | ||
if keys := ctx.globals_keys - self.globals.keys(): |
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.
Function Template._get_default_module_async
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
for template_line, code_line in reversed(self.debug_info): | ||
if code_line <= lineno: | ||
return template_line | ||
return 1 | ||
return next( | ||
( | ||
template_line | ||
for template_line, code_line in reversed(self.debug_info) | ||
if code_line <= lineno | ||
), | ||
1, | ||
) |
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.
Function Template.get_corresponding_lineno
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
if self._uptodate is None: | ||
return True | ||
return self._uptodate() | ||
return True if self._uptodate is None else self._uptodate() |
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.
Function Template.is_up_to_date
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
)
if self.name is None: | ||
name = f"memory:{id(self):x}" | ||
else: | ||
name = repr(self.name) | ||
name = f"memory:{id(self):x}" if self.name is None else repr(self.name) |
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.
Function Template.__repr__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if self.__name__ is None: | ||
name = f"memory:{id(self):x}" | ||
else: | ||
name = repr(self.__name__) | ||
name = f"memory:{id(self):x}" if self.__name__ is None else repr(self.__name__) |
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.
Function TemplateModule.__repr__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if isinstance(value, str): | ||
return int(value, base) | ||
|
||
return int(value) | ||
return int(value, base) if isinstance(value, str) else int(value) |
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.
Function do_int
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
)
items_per_slice = length // slices | ||
slices_with_extra = length % slices | ||
items_per_slice, slices_with_extra = divmod(length, slices) |
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.
Function sync_do_slice
refactored with the following changes:
- Simplify division expressions (
simplify-division
)
return str(value) | ||
return value |
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.
Function do_mark_unsafe
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
name = str(name) | ||
name = name |
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.
Function do_attr
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if parent is None: | ||
level = 0 | ||
else: | ||
level = parent.level + 1 | ||
|
||
level = 0 if parent is None else parent.level + 1 |
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.
Function Symbols.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if self.parent is not None: | ||
return self.parent.find_load(target) | ||
|
||
return None | ||
return self.parent.find_load(target) if self.parent is not None else None |
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.
Function Symbols.find_load
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
)
if self.parent is not None: | ||
return self.parent.find_ref(name) | ||
|
||
return None | ||
return self.parent.find_ref(name) if self.parent is not None else None |
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.
Function Symbols.find_ref
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
)
if ":" in expr: | ||
return expr.split(":", 1) == [self.type, self.value] | ||
|
||
return False | ||
return expr.split(":", 1) == [self.type, self.value] if ":" in expr else False |
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.
Function Token.test
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
)
if self.current.test(expr): | ||
return next(self) | ||
|
||
return None | ||
return next(self) if self.current.test(expr) else None |
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.
Function TokenStream.next_if
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
)
stack.append(state + "_begin") | ||
stack.append(f"{state}_begin") |
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.
Function Lexer.tokeniter
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Split conditional into multiple branches [×2] (
split-or-ifs
) - Merge duplicate blocks in conditional [×2] (
merge-duplicate-blocks
) - Remove redundant conditional [×2] (
remove-redundant-if
)
if eval_ctx.autoescape: | ||
return Markup(expr) | ||
return expr | ||
return Markup(expr) if eval_ctx.autoescape else expr |
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.
Function MarkSafeIfAutoescape.as_const
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
)
test = None | ||
if self.stream.skip_if("name:if"): | ||
test = self.parse_expression() | ||
test = self.parse_expression() if self.stream.skip_if("name:if") else None |
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.
Function Parser.parse_for
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace if statement with if expression (
assign-if-exp
)
self.stream.skip_if("name:" + node.name) | ||
self.stream.skip_if(f"name:{node.name}") |
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.
Function Parser.parse_block
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if with_condexpr: | ||
return self.parse_condexpr() | ||
return self.parse_or() | ||
return self.parse_condexpr() if with_condexpr else self.parse_or() |
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.
Function Parser.parse_expression
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
)
if self.stream.skip_if("name:else"): | ||
expr3 = self.parse_condexpr() | ||
else: | ||
expr3 = None | ||
expr3 = self.parse_condexpr() if self.stream.skip_if("name:else") else None |
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.
Function Parser.parse_condexpr
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!