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

feat(deps): remove drfaddons dependency (Sourcery refactored) #209

Open
wants to merge 1 commit into
base: sumit/remove-drfaddons
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Oct 8, 2022

Pull Request #208 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

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:

Review changes via command line

To manually merge these changes, make sure you're on the sumit/remove-drfaddons branch, then run:

git fetch origin sourcery/sumit/remove-drfaddons
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from sumit4613 October 8, 2022 16:29
@sourcery-ai
Copy link
Contributor Author

sourcery-ai bot commented Oct 8, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.53%.

Quality metrics Before After Change
Complexity 6.93 ⭐ 6.87 ⭐ -0.06 👍
Method Length 65.82 🙂 65.54 🙂 -0.28 👍
Working memory 6.20 🙂 6.46 🙂 0.26 👎
Quality 73.73% 🙂 73.20% 🙂 -0.53% 👎
Other metrics Before After Change
Lines 732 725 -7
Changed files Quality Before Quality After Quality Change
drf_user/init.py 53.28% 🙂 52.02% 🙂 -1.26% 👎
drf_user/serializers.py 84.12% ⭐ 83.52% ⭐ -0.60% 👎
drf_user/utils.py 70.04% 🙂 69.75% 🙂 -0.29% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
drf_user/init.py update_user_settings 34 ⛔ 131 😞 9 🙂 41.44% 😞 Refactor to reduce nesting. Try splitting into smaller methods
drf_user/utils.py send_message 9 🙂 158 😞 8 🙂 57.58% 🙂 Try splitting into smaller methods
drf_user/utils.py send_otp 2 ⭐ 111 🙂 11 😞 63.64% 🙂 Extract out complex expressions
drf_user/utils.py generate_otp 4 ⭐ 143 😞 8 🙂 63.96% 🙂 Try splitting into smaller methods
drf_user/utils.py validate_otp 4 ⭐ 125 😞 7 🙂 68.40% 🙂 Try splitting into smaller methods

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!

Help us improve this quality report!

@sourcery-ai sourcery-ai bot force-pushed the sourcery/sumit/remove-drfaddons branch 3 times, most recently from c8b305d to 830e39b Compare October 15, 2022 07:56
@sourcery-ai sourcery-ai bot force-pushed the sourcery/sumit/remove-drfaddons branch from 830e39b to 634c789 Compare October 21, 2022 04:15
custom_settings = getattr(settings, "USER_SETTINGS", None)

if custom_settings:
if custom_settings := getattr(settings, "USER_SETTINGS", None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function update_user_settings refactored with the following changes:

Comment on lines -193 to -205
user = self.get_user(attrs.get("prop"), attrs.get("destination"))
if user := self.get_user(attrs.get("prop"), attrs.get("destination")):
attrs["email"] = user.email
attrs["user"] = user

if not user:
else:
if attrs["is_login"]:
raise NotFound(_("No user exists with provided details"))
if "email" not in attrs.keys() and "verify_otp" not in attrs.keys():
raise serializers.ValidationError(
_("Email field is compulsory while verifying a non-existing user's OTP.")
)
else:
attrs["email"] = user.email
attrs["user"] = user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function OTPSerializer.validate refactored with the following changes:

Comment on lines -331 to -336
user = self.get_user(attrs.get("email"))

if not user:
if user := self.get_user(attrs.get("email")):
return attrs
else:
raise NotFound(_("User with the provided email does not exist."))

return attrs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function PasswordResetSerializer.validate refactored with the following changes:

x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
if x_forwarded_for:
if x_forwarded_for := request.META.get("HTTP_X_FORWARDED_FOR"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function get_client_ip refactored with the following changes:

Comment on lines -254 to +253
match = re.match(r"^[6-9]\d{9}$", str(mobile))
match = re.match(r"^[6-9]\d{9}$", mobile)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function is_mobile_valid 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

0 participants