-
Notifications
You must be signed in to change notification settings - Fork 40
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 Starbot ⭐ refactored dgk/django-business-logic #42
base: master
Are you sure you want to change the base?
Conversation
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) | ||
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py)[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 get_version
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
for d in ('dist', 'build', '{}.egg-info'.format(NAME.replace('-', '_'))): | ||
for d in ('dist', 'build', f"{NAME.replace('-', '_')}.egg-info"): |
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 clean
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
long_description=codecs.open(abs_path('README.rst'), encoding='utf-8').read(), | ||
long_description=codecs.open( | ||
abs_path('README.rst'), encoding='utf-8' | ||
).read(), | ||
author=AUTHOR, | ||
author_email=AUTHOR_EMAIL, | ||
url=URL, | ||
download_url='{}/archive/{}.tar.gz'.format(URL, version), | ||
download_url=f'{URL}/archive/{version}.tar.gz', |
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.
Lines 83-128
refactored with the following changes:
- Replace call to format with f-string. [×2] (
use-fstring-for-formatting
)
raise TypeError('Incorrect kwarg {}'.format(k)) | ||
raise TypeError(f'Incorrect kwarg {k}') |
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 ContextConfig.__init__
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
method_name = 'visit_{}'.format(camel_case_to_snake_case(cls.__name__)) | ||
method_name = f'visit_{camel_case_to_snake_case(cls.__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 BlocklyXmlBuilder.visit
refactored with the following changes:
- Replace call to format with f-string. [×2] (
use-fstring-for-formatting
)
method_name = 'visit_block_{}'.format(node.get('type')) | ||
method_name = f"visit_block_{node.get('type')}" |
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 BlocklyXmlParser.visit_block
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
method_name = 'visit_field_{}'.format(node.get('name').lower()) | ||
method_name = f"visit_field_{node.get('name').lower()}" |
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 BlocklyXmlParser.visit_field
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
|
||
|
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.
Lines 22-513
refactored with the following changes:
- Unwrap a constant iterable constructor. [×2] (
unwrap-iterable-construction
)
if not self.frames: | ||
return None | ||
return self.frames[-1] | ||
return self.frames[-1] if self.frames 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 Context._frame
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if not self.config.cache: | ||
return node.get_children().all() | ||
|
||
return super(Context, self).get_children(node) | ||
return ( | ||
super(Context, self).get_children(node) | ||
if self.config.cache | ||
else node.get_children().all() | ||
) |
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 Context.get_children
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
value = value[:LOG_ENTRY_VALUE_LENGTH - 3] + '...' | ||
value = f'{value[:LOG_ENTRY_VALUE_LENGTH - 3]}...' |
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 Logger.prepare_value
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'Node {}({}): {}'.format(self.id, self.content_type, self.content_object) | ||
return f'Node {self.id}({self.content_type}): {self.content_object}' |
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 Node.__str__
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
node_kwargs = dict() | ||
node_kwargs = {} | ||
|
||
if self.clone is None: | ||
clone = self.clone = Node.add_root(**node_kwargs) | ||
clone.rgt = node.rgt | ||
clone.lft = node.lft | ||
clone.save() | ||
else: | ||
node_kwargs.update( | ||
dict([(field_name, getattr(node, field_name)) for field_name in ('rgt', 'lft', 'depth')])) | ||
node_kwargs.update(dict(tree_id=self.clone.tree_id)) | ||
node_kwargs |= dict( | ||
[ | ||
(field_name, getattr(node, field_name)) | ||
for field_name in ('rgt', 'lft', 'depth') | ||
] | ||
) | ||
|
||
node_kwargs |= dict(tree_id=self.clone.tree_id) | ||
clone = Node.objects.create(**node_kwargs) | ||
clone.save() | ||
|
||
clone.save() |
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 Node.clone.CloneVisitor.visit
refactored with the following changes:
- Replace dict() with {} (
dict-literal
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Merge dictionary updates via the union operator. [×2] (
dict-assign-update-to-union
)
self._child_by_parent_id = {} | ||
for parent in tree: | ||
self._child_by_parent_id[parent.id] = [ | ||
node for node in tree | ||
if node.lft >= parent.lft and node.lft <= parent.rgt - 1 and node.depth == parent.depth + 1 | ||
self._child_by_parent_id = { | ||
parent.id: [ | ||
node | ||
for node in tree | ||
if node.lft >= parent.lft | ||
and node.lft <= parent.rgt - 1 | ||
and node.depth == parent.depth + 1 | ||
] | ||
for parent in tree | ||
} |
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 NodeCache._initialize
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
)
return '{}.{}'.format(self.program_argument.name, self.name) | ||
return f'{self.program_argument.name}.{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 ProgramArgumentField.get_variable_name
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
return u'%s %s' % (self.first_name, self.last_name) | ||
return f'{self.first_name} {self.last_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 Author.__str__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
fields = {} | ||
for field in self.field_list: | ||
fields[field] = ProgramArgumentField.objects.create( | ||
return { | ||
field: ProgramArgumentField.objects.create( | ||
name=field, | ||
program_argument=argument, | ||
) | ||
|
||
return fields | ||
for field in self.field_list | ||
} |
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 ProgramTestBase.create_argument_fields
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
elif node == node1: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node2: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node1_1: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node2_1: | ||
elif node in [node1, node2, node1_1, node2_1]: | ||
self.assertEqual(2, len(context.frames)) |
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 FrameTest.test_switch_frames.on_interpret_enter
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
elif node == node1: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node2: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node1_1: | ||
self.assertEqual(2, len(context.frames)) | ||
elif node == node2_1: | ||
elif node in [node1, node2, node1_1, node2_1]: | ||
self.assertEqual(2, len(context.frames)) |
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 FrameTest.test_switch_frames.on_interpret_leave
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
0.0 // 0.0 | ||
1.0 |
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 LogTest.test_log_exception
refactored with the following changes:
- Simplify binary operation (
bin-op-identity
)
self.assertEqual('{}.{}'.format(self.argument.name, 'int_value'), int_value_field.variable_definition.name) | ||
self.assertEqual( | ||
f'{self.argument.name}.int_value', | ||
int_value_field.variable_definition.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 ProgramTest.test_program_argument_field_variable_definition
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
self.assertEqual('{}.{}'.format(self.argument.name, 'int_value'), variable_definition.name) | ||
self.assertEqual(f'{self.argument.name}.int_value', variable_definition.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 ProgramTest.test_save_program_argument_change_field_variable_definition
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
variable_definitions = {} | ||
|
||
for field in ( | ||
variable_definitions = { | ||
field: VariableDefinition.objects.create(name=field) | ||
for field in ( | ||
'test_model.int_value', | ||
'test_model.not_exists', | ||
'test_model.foreign_value.string_value', | ||
'test_model.foreign_value.not_exists', | ||
): | ||
variable_definitions[field] = VariableDefinition.objects.create(name=field) | ||
) | ||
} | ||
|
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 VariableTest.test_get_variable_returns_recursive_attribute_undefined
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
)
dict(data=dict(object_id=obj_cls.objects.create(**obj_kwargs).id, content_type_id=content_type_id)) | ||
for x in range(pow(2, level)) | ||
dict( | ||
data=dict( | ||
object_id=obj_cls.objects.create(**obj_kwargs).id, | ||
content_type_id=content_type_id, | ||
) | ||
) | ||
for _ in range(pow(2, level)) | ||
] | ||
|
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 symmetric_tree
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
print('\n'.join([ | ||
'%s %s %s %s %s %s' % (n.pk, getattr(n, '%s_id' % opts.parent_attr) or '-', getattr(n, opts.tree_id_attr), | ||
getattr(n, opts.level_attr), getattr(n, opts.left_attr), getattr(n, opts.right_attr)) | ||
for n in nodes | ||
])) | ||
print( | ||
'\n'.join( | ||
[ | ||
f"{n.pk} {getattr(n, f'{opts.parent_attr}_id') or '-'} {getattr(n, opts.tree_id_attr)} {getattr(n, opts.level_attr)} {getattr(n, opts.left_attr)} {getattr(n, opts.right_attr)}" | ||
for n in nodes | ||
] | ||
) | ||
) |
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 print_tree_details
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
ret = super(Client, self).post( | ||
path, data=data, content_type=content_type, follow=follow, HTTP_X_REQUESTED_WITH='XMLHttpRequest', **extra) | ||
return ret | ||
return super(Client, self).post( | ||
path, | ||
data=data, | ||
content_type=content_type, | ||
follow=follow, | ||
HTTP_X_REQUESTED_WITH='XMLHttpRequest', | ||
**extra | ||
) |
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 JSONClient.post
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
ret = super(Client, self).put( | ||
path, data=data, content_type=content_type, follow=follow, HTTP_X_REQUESTED_WITH='XMLHttpRequest', **extra) | ||
return ret | ||
return super(Client, self).put( | ||
path, | ||
data=data, | ||
content_type=content_type, | ||
follow=follow, | ||
HTTP_X_REQUESTED_WITH='XMLHttpRequest', | ||
**extra | ||
) |
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 JSONClient.put
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
ret = super(Client, self).delete( | ||
path, data=data, content_type=content_type, follow=follow, HTTP_X_REQUESTED_WITH='XMLHttpRequest', **extra) | ||
return ret | ||
return super(Client, self).delete( | ||
path, | ||
data=data, | ||
content_type=content_type, | ||
follow=follow, | ||
HTTP_X_REQUESTED_WITH='XMLHttpRequest', | ||
**extra | ||
) |
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 JSONClient.delete
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
fields = dict((x['name'], x) for x in argument['fields']) | ||
fields = {x['name']: x for x in argument['fields']} |
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 ProgramInterfaceTest.test_program_interface_view
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
self.test_models = [] | ||
|
||
for i in range(11): | ||
self.test_models.append(Model.objects.create(string_value='str_{}'.format(str(i) * 3))) | ||
self.test_models = [ | ||
Model.objects.create(string_value=f'str_{str(i) * 3}') | ||
for i in range(11) | ||
] |
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 ReferenceListTest.setUp
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Replace call to format with f-string. (
use-fstring-for-formatting
)
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
master
branch, then run: