-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored rohitkumar93/full-stack-fastapi-postgresql #1
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
base: master
Are you sure you want to change the base?
Conversation
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "test_email.html") as f: | ||
template_str = f.read() | ||
template_str = Path( | ||
Path(settings.EMAIL_TEMPLATES_DIR) / "test_email.html" | ||
).read_text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function send_test_email
refactored with the following changes:
- Simplify basic file reads with
pathlib
(path-read
)
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "reset_password.html") as f: | ||
template_str = f.read() | ||
template_str = Path( | ||
Path(settings.EMAIL_TEMPLATES_DIR) / "reset_password.html" | ||
).read_text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function send_reset_password_email
refactored with the following changes:
- Simplify basic file reads with
pathlib
(path-read
)
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "new_account.html") as f: | ||
template_str = f.read() | ||
template_str = Path( | ||
Path(settings.EMAIL_TEMPLATES_DIR) / "new_account.html" | ||
).read_text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function send_new_account_email
refactored with the following changes:
- Simplify basic file reads with
pathlib
(path-read
)
encoded_jwt = jwt.encode( | ||
{"exp": exp, "nbf": now, "sub": email}, settings.SECRET_KEY, algorithm="HS256", | ||
return jwt.encode( | ||
{"exp": exp, "nbf": now, "sub": email}, | ||
settings.SECRET_KEY, | ||
algorithm="HS256", | ||
) | ||
return encoded_jwt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function generate_password_reset_token
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
user = crud.user.get(db, id=token_data.sub) | ||
if not user: | ||
if user := crud.user.get(db, id=token_data.sub): | ||
return user | ||
else: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
return user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_current_user
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM) | ||
return encoded_jwt | ||
return jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function create_access_token
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
user = self.get_by_email(db, email=email) | ||
if not user: | ||
return None | ||
if not verify_password(password, user.hashed_password): | ||
if user := self.get_by_email(db, email=email): | ||
return user if verify_password(password, user.hashed_password) else None | ||
else: | ||
return None | ||
return user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CRUDUser.authenticate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow [×2] (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
) - Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
)
headers = {"Authorization": f"Bearer {auth_token}"} | ||
return headers | ||
return {"Authorization": f"Bearer {auth_token}"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function user_authentication_headers
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
user = crud.user.get_by_email(db, email=email) | ||
if not user: | ||
user_in_create = UserCreate(username=email, email=email, password=password) | ||
user = crud.user.create(db, obj_in=user_in_create) | ||
else: | ||
if user := crud.user.get_by_email(db, email=email): | ||
user_in_update = UserUpdate(password=password) | ||
user = crud.user.update(db, db_obj=user, obj_in=user_in_update) | ||
|
||
else: | ||
user_in_create = UserCreate(username=email, email=email, password=password) | ||
user = crud.user.create(db, obj_in=user_in_create) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function authentication_token_from_email
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Swap if/else branches (
swap-if-else-branches
)
headers = {"Authorization": f"Bearer {a_token}"} | ||
return headers | ||
return {"Authorization": f"Bearer {a_token}"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_superuser_token_headers
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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: