Skip to content

Sourcery refactored develop branch#1

Open
sourcery-ai[bot] wants to merge 1 commit into
developfrom
sourcery/develop
Open

Sourcery refactored develop branch#1
sourcery-ai[bot] wants to merge 1 commit into
developfrom
sourcery/develop

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Dec 1, 2021

Branch develop 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 develop branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from MattFisher December 1, 2021 02:14
Comment thread denorm/daemon.py
@@ -29,6 +29,7 @@
Stevens, W. Richard. I{Unix Network Programming} (Addison-Wesley, 1990).
"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 63-68 refactored with the following changes:

Comment thread denorm/daemon.py
Comment on lines -199 to +195
for fd in range(0, maxfd):
for fd in range(maxfd):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _redirectFileDescriptors refactored with the following changes:

Comment thread denorm/denorms.py
Comment on lines -28 to +55
if instance.pk:
if not instance.pk:
return
# Need a primary key to do m2m stuff
for m2m in sender._meta.local_many_to_many:
for m2m in sender._meta.local_many_to_many:
# This gets us all m2m fields, so limit it to just those that are denormed
if hasattr(m2m, 'denorm'):
# Does some extra jiggery-pokery for "through" m2m models.
# May not work under lots of conditions.
try:
remote = m2m.remote_field # Django>=1.10
except AttributeError:
remote = m2m.rel
if hasattr(remote, 'through_model'):
# Clear exisiting through records (bit heavy handed?)
kwargs = {m2m.related.var_name: instance}

# Can't use m2m_column_name in a filter
# kwargs = { m2m.m2m_column_name(): instance.pk, }
remote.through_model.objects.filter(**kwargs).delete()

values = m2m.denorm.func(instance)
for value in values:
kwargs.update({m2m.m2m_reverse_name(): value.pk})
remote.through_model.objects.create(**kwargs)
if hasattr(m2m, 'denorm'):
# Does some extra jiggery-pokery for "through" m2m models.
# May not work under lots of conditions.
try:
remote = m2m.remote_field # Django>=1.10
except AttributeError:
remote = m2m.rel
if hasattr(remote, 'through_model'):
# Clear exisiting through records (bit heavy handed?)
kwargs = {m2m.related.var_name: instance}

# Can't use m2m_column_name in a filter
# kwargs = { m2m.m2m_column_name(): instance.pk, }
remote.through_model.objects.filter(**kwargs).delete()

values = m2m.denorm.func(instance)
for value in values:
kwargs[m2m.m2m_reverse_name()] = value.pk
remote.through_model.objects.create(**kwargs)

else:
values = m2m.denorm.func(instance)
setattr(instance, m2m.attname, values)
else:
values = m2m.denorm.func(instance)
setattr(instance, m2m.attname, values)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function many_to_many_pre_save refactored with the following changes:

Comment thread denorm/denorms.py
Comment on lines -60 to +61
for m2m in sender._meta.local_many_to_many:
if hasattr(m2m, 'denorm'):
return True
return False
return any(hasattr(m2m, 'denorm') for m2m in sender._meta.local_many_to_many)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function many_to_many_post_save.check_resave refactored with the following changes:

  • Use any() instead of for loop (use-any)

Comment thread denorm/denorms.py
Comment on lines -77 to +79
if hasattr(field, 'denorm'):
if not field.denorm.model._meta.swapped:
alldenorms.append(field.denorm)
if (
hasattr(field, 'denorm')
and not field.denorm.model._meta.swapped
):
alldenorms.append(field.denorm)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_alldenorms refactored with the following changes:

Comment thread denorm/fields.py
Comment on lines -338 to +337
dbfield = CachedField(func, cache, *args, **kwargs)
return dbfield
return CachedField(func, cache, *args, **kwargs)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function cached.deco refactored with the following changes:

Comment thread denorm/db/base.py
else:
self.connection = connection

self.connection = connections[self.using] if self.using else connection
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trigger.__init__ refactored with the following changes:

Comment thread denorm/db/base.py
Comment on lines -152 to +149
if self.using:
self.connection = connections[self.using]
else:
self.connection = connection
self.connection = connections[self.using] if self.using else connection
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriggerSet.__init__ refactored with the following changes:

Comment on lines -25 to +28
params = []
if isinstance(self.values, TriggerNestedSelect):
sql, nested_params = self.values.sql()
values = "(" + sql + ")"
params = []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TriggerActionInsert.sql refactored with the following changes:

Comment on lines -317 to -330
# FIXME, set and de-set middleware values
f1 = models.Forum.objects.create(title="forumone")
m1 = models.Member.objects.create(first_name="first1", name="last1")
p1 = models.Post.objects.create(forum=f1, author=m1)

self.assertEqual(models.Post.objects.get(id=p1.id).author_name, "last1")

self.client.login(username="testuser", password="testuser")
self.client.post("/admin/denorm_testapp/member/%s/" % (m1.pk), {
'name': 'last2',
'first_name': 'first2',
})

self.assertEqual(models.Post.objects.get(id=p1.id).author_name, "last2")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestDenormalisation.test_middleware refactored with the following changes:

This removes the following comments ( why? ):

# FIXME, set and de-set middleware values

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