Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Sourcery refactored master branch #2

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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 28, 2020

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

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

if value and not datatype == attribute.TYPE_ENUM: #enum done above
if value and datatype != attribute.TYPE_ENUM: #enum done above
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseDynamicEntityForm._build_dynamic_fields refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -240 to +246
if self.datatype == self.TYPE_ENUM:
if value not in self.enum_group.enums.all():
raise ValidationError(_(u"%(enum)s is not a valid choice "
u"for %(attr)s") % \
{'enum': value, 'attr': self})
if (
self.datatype == self.TYPE_ENUM
and value not in self.enum_group.enums.all()
):
raise ValidationError(_(u"%(enum)s is not a valid choice "
u"for %(attr)s") % \
{'enum': value, 'attr': 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 Attribute.validate_value refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

Comment on lines -277 to +279
if not self.datatype == Attribute.TYPE_ENUM:
if self.datatype != Attribute.TYPE_ENUM:
Copy link
Author

Choose a reason for hiding this comment

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

Function Attribute.get_choices refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -300 to +307
if value == None or value == '':
if value in [None, '']:
return
value_obj = Value.objects.create(entity_ct=ct,
entity_id=entity.pk,
attribute=self)
if value == None or value == '':
if value is None or 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 Attribute.save_value refactored with the following changes:

  • Use x is None rather than x == None (none-compare)
  • Replace multiple comparisons of same variable with in operator (merge-comparisons)

Comment on lines -374 to +384
if self.attribute.datatype == Attribute.TYPE_ENUM and \
self.value_enum:
if self.value_enum not in self.attribute.enum_group.enums.all():
raise ValidationError(_(u"%(choice)s is not a valid " \
u"choice for %s(attribute)") % \
{'choice': self.value_enum,
'attribute': self.attribute})
if (
self.attribute.datatype == Attribute.TYPE_ENUM
and self.value_enum
and self.value_enum not in self.attribute.enum_group.enums.all()
):
raise ValidationError(_(u"%(choice)s is not a valid " \
u"choice for %s(attribute)") % \
{'choice': self.value_enum,
'attribute': self.attribute})
Copy link
Author

Choose a reason for hiding this comment

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

Function Value.clean refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

Comment on lines -499 to +503
values_dict = dict()
values_dict = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function Entity.get_values_dict refactored with the following changes:

  • Replace dict() with {} (dict-literal)

if not (type(value) == unicode or type(value) == str):
if not type(value) in [unicode, str]:
Copy link
Author

Choose a reason for hiding this comment

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

Function validate_text refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)

if not type(value) == bool:
if type(value) != bool:
Copy link
Author

Choose a reason for hiding this comment

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

Function validate_bool refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jun 28, 2020

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.02 out of 10.

Before After Change
Quality 9.25 9.27 0.02
Complexity 1.27 1.16 -0.11
Method Length 25.56 25.31 -0.25
Lines 447 451 4
Changed files Quality Before Quality After Quality Change
eav/forms.py 8.57 8.57 0.0 ⬆️
eav/models.py 9.34 9.35 0.02 ⬆️
eav/validators.py 9.34 9.37 0.03 ⬆️

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it via email or our Gitter!

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

Successfully merging this pull request may close these issues.

1 participant