Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 24, 2023

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:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Ntrystan July 24, 2023 04:45
Copy link
Author

@sourcery-ai sourcery-ai bot left a 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):
Copy link
Author

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:

out.append(a)
out.append(b)
out.extend((a, b))
Copy link
Author

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:

if b:
return async_func(*args, **kwargs)

return normal_func(*args, **kwargs)
return async_func(*args, **kwargs) if b else normal_func(*args, **kwargs)
Copy link
Author

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:

self.write("(" + op)
self.write(f"({op}")
Copy link
Author

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:

if stream is None:
return generator.stream.getvalue() # type: ignore

return None
return generator.stream.getvalue() if stream is None else None
Copy link
Author

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:

This removes the following comments ( why? ):

# type: ignore

Comment on lines -102 to +99
if type(cache) is dict:
return {}

return LRUCache(cache.capacity) # type: ignore
return {} if type(cache) is dict else LRUCache(cache.capacity)
Copy link
Author

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:

This removes the following comments ( why? ):

# type: ignore

Comment on lines -538 to +532
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)
Copy link
Author

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:

Comment on lines -636 to +626
source = str(source)
source = source
Copy link
Author

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:

Comment on lines -655 to +645
str(source),
source,
Copy link
Author

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:

Comment on lines -1442 to +1432
keys = ctx.globals_keys - self.globals.keys()

if keys:
if keys := ctx.globals_keys - self.globals.keys():
Copy link
Author

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:

Comment on lines -1456 to +1444
keys = ctx.globals_keys - self.globals.keys()

if keys:
if keys := ctx.globals_keys - self.globals.keys():
Copy link
Author

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:

Comment on lines -1486 to +1479
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,
)
Copy link
Author

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)

Comment on lines -1494 to +1484
if self._uptodate is None:
return True
return self._uptodate()
return True if self._uptodate is None else self._uptodate()
Copy link
Author

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:

Comment on lines -1510 to +1498
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)
Copy link
Author

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:

Comment on lines -1550 to +1535
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__)
Copy link
Author

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:

Comment on lines -954 to +935
if isinstance(value, str):
return int(value, base)

return int(value)
return int(value, base) if isinstance(value, str) else int(value)
Copy link
Author

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:

Comment on lines -1042 to +1020
items_per_slice = length // slices
slices_with_extra = length % slices
items_per_slice, slices_with_extra = divmod(length, slices)
Copy link
Author

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:

Comment on lines -1341 to +1318
return str(value)
return value
Copy link
Author

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:

Comment on lines -1383 to +1360
name = str(name)
name = name
Copy link
Author

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:

if parent is None:
level = 0
else:
level = parent.level + 1

level = 0 if parent is None else parent.level + 1
Copy link
Author

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:

Comment on lines -63 to +59
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
Copy link
Author

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:

Comment on lines -72 to +65
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
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -369 to +366
if self.current.test(expr):
return next(self)

return None
return next(self) if self.current.test(expr) else None
Copy link
Author

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:

Comment on lines -693 to +687
stack.append(state + "_begin")
stack.append(f"{state}_begin")
Copy link
Author

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:

Comment on lines -1109 to +1102
if eval_ctx.autoescape:
return Markup(expr)
return expr
return Markup(expr) if eval_ctx.autoescape else expr
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -323 to +321
self.stream.skip_if("name:" + node.name)
self.stream.skip_if(f"name:{node.name}")
Copy link
Author

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:

Comment on lines -520 to +518
if with_condexpr:
return self.parse_condexpr()
return self.parse_or()
return self.parse_condexpr() if with_condexpr else self.parse_or()
Copy link
Author

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:

Comment on lines -531 to +527
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
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants