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

Use deep copy so that all arguments are copied by value (Sourcery refactored) #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Apr 30, 2021

Pull Request #66 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/shosca/django-rest-witchcraft pull/66/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Comment on lines -386 to 394
assert not (_fields is None and exclude is None), (
assert _fields is not None or exclude is not None, (
"Creating a ModelSerializer without either the 'fields' attribute "
"or the 'exclude' attribute has been deprecated since 3.3.0, "
"and is now disallowed. Add an explicit fields = '__all__' to the "
"{serializer_class} serializer.".format(serializer_class=self.__class__.__name__),
"{serializer_class} serializer.".format(
serializer_class=self.__class__.__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 ModelSerializer.get_field_names refactored with the following changes:

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

Comment on lines -577 to +584
backrefs = set()
for key, rel in target_model_info.relationships.items():
if rel.related_model == self.model:
backrefs.add(key)
backrefs = {
key
for key, rel in target_model_info.relationships.items()
if rel.related_model == self.model
}
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelSerializer.get_nested_relationship_fields refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Apr 30, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.06%.

Quality metrics Before After Change
Complexity 8.23 ⭐ 8.19 ⭐ -0.04 👍
Method Length 58.00 ⭐ 57.88 ⭐ -0.12 👍
Working memory 10.55 😞 10.57 😞 0.02 👎
Quality 64.46% 🙂 64.52% 🙂 0.06% 👍
Other metrics Before After Change
Lines 784 788 4
Changed files Quality Before Quality After Quality Change
rest_witchcraft/serializers.py 64.46% 🙂 64.52% 🙂 0.06% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
rest_witchcraft/serializers.py ModelSerializer.perform_update 43 ⛔ 190 😞 17 ⛔ 20.57% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
rest_witchcraft/serializers.py ModelSerializer.get_field_names 17 🙂 190 😞 13 😞 38.32% 😞 Try splitting into smaller methods. Extract out complex expressions
rest_witchcraft/serializers.py BaseSerializer.build_standard_field_kwargs 11 🙂 140 😞 19 ⛔ 41.78% 😞 Try splitting into smaller methods. Extract out complex expressions
rest_witchcraft/serializers.py ModelSerializer.build_nested_field 6 ⭐ 145 😞 14 😞 50.91% 🙂 Try splitting into smaller methods. Extract out complex expressions
rest_witchcraft/serializers.py ExpandableModelSerializer.to_representation 4 ⭐ 91 🙂 22 ⛔ 52.92% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


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 by mentioning @sourcery-ai in a comment.

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.

1 participant