Sourcery Starbot ⭐ refactored rohitkumar93/full-stack-fastapi-postgresql#1
Sourcery Starbot ⭐ refactored rohitkumar93/full-stack-fastapi-postgresql#1SourceryAI wants to merge 1 commit intorohitkumar93:masterfrom
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.
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.
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.
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.
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.
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)
| to_encode = {"exp": expire, "sub": str(subject)} | ||
| 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.
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.
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)
| auth_token = response["access_token"] | ||
| headers = {"Authorization": f"Bearer {auth_token}"} | ||
| return headers | ||
| return {"Authorization": f"Bearer {auth_token}"} |
There was a problem hiding this comment.
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.
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)
| a_token = tokens["access_token"] | ||
| headers = {"Authorization": f"Bearer {a_token}"} | ||
| return headers | ||
| return {"Authorization": f"Bearer {a_token}"} |
There was a problem hiding this comment.
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
masterbranch, then run: