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 Starbot ⭐ refactored dgk/django-business-logic #42

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

Conversation

sourcery-ai-bot
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/django-business-logic master
git merge --ff-only FETCH_HEAD
git reset HEAD^

return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py)[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 get_version refactored with the following changes:

for d in ('dist', 'build', '{}.egg-info'.format(NAME.replace('-', '_'))):
for d in ('dist', 'build', f"{NAME.replace('-', '_')}.egg-info"):
Copy link
Author

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:

Comment on lines -83 to +89
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',
Copy link
Author

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:

raise TypeError('Incorrect kwarg {}'.format(k))
raise TypeError(f'Incorrect kwarg {k}')
Copy link
Author

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:

method_name = 'visit_{}'.format(camel_case_to_snake_case(cls.__name__))
method_name = f'visit_{camel_case_to_snake_case(cls.__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 BlocklyXmlBuilder.visit refactored with the following changes:

Comment on lines -164 to +166
method_name = 'visit_block_{}'.format(node.get('type'))
method_name = f"visit_block_{node.get('type')}"
Copy link
Author

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:

Comment on lines -196 to +198
method_name = 'visit_field_{}'.format(node.get('name').lower())
method_name = f"visit_field_{node.get('name').lower()}"
Copy link
Author

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:

Comment on lines 8 to 9


Copy link
Author

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:

if not self.frames:
return None
return self.frames[-1]
return self.frames[-1] if self.frames 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 Context._frame refactored with the following changes:

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

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:

value = value[:LOG_ENTRY_VALUE_LENGTH - 3] + '...'
value = f'{value[:LOG_ENTRY_VALUE_LENGTH - 3]}...'
Copy link
Author

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:

return 'Node {}({}): {}'.format(self.id, self.content_type, self.content_object)
return f'Node {self.id}({self.content_type}): {self.content_object}'
Copy link
Author

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:

Comment on lines -120 to +137
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()
Copy link
Author

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:

Comment on lines -282 to +296
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
}
Copy link
Author

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:

return '{}.{}'.format(self.program_argument.name, self.name)
return f'{self.program_argument.name}.{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 ProgramArgumentField.get_variable_name refactored with the following changes:

return u'%s %s' % (self.first_name, self.last_name)
return f'{self.first_name} {self.last_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 Author.__str__ refactored with the following changes:

Comment on lines -55 to +61
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
}
Copy link
Author

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:

Comment on lines -47 to 54
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))
Copy link
Author

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:

Comment on lines -60 to 67
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))
Copy link
Author

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:

0.0 // 0.0
1.0
Copy link
Author

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:

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

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:

Comment on lines -42 to +45
self.assertEqual('{}.{}'.format(self.argument.name, 'int_value'), variable_definition.name)
self.assertEqual(f'{self.argument.name}.int_value', variable_definition.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 ProgramTest.test_save_program_argument_change_field_variable_definition refactored with the following changes:

Comment on lines -55 to +64
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)
)
}

Copy link
Author

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:

Comment on lines -79 to 87
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))
]

Copy link
Author

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:

Comment on lines -134 to +147
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
]
)
)
Copy link
Author

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:

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

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:

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

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:

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

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:

fields = dict((x['name'], x) for x in argument['fields'])
fields = {x['name']: x for x in argument['fields']}
Copy link
Author

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:

Comment on lines -50 to +53
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)
]
Copy link
Author

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:

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.

None yet

1 participant