Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Oct 27, 2023

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^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from dodo888619 October 27, 2023 08:19
Comment thread pydantic_tutorial.py
print("\033[31m2. --- 校验失败处理 ---\033[0m")
try:
User(id=1, signup_ts=datetime.today(), friends=[1, 2, "not number"])
User(id=1, signup_ts=datetime.now(), friends=[1, 2, "not number"])
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 49-49 refactored with the following changes:

Comment thread coronavirus/main.py
def create_city(city: schemas.CreateCity, db: Session = Depends(get_db)):
db_city = crud.get_city_by_name(db, name=city.province)
if db_city:
if db_city := crud.get_city_by_name(db, name=city.province):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function create_city refactored with the following changes:

Comment thread coronavirus/main.py
Comment on lines -50 to +49
cities = crud.get_cities(db, skip=skip, limit=limit)
return cities
return crud.get_cities(db, skip=skip, limit=limit)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_cities refactored with the following changes:

Comment thread coronavirus/main.py
Comment on lines -63 to +61
data = crud.get_data(db, city=city, skip=skip, limit=limit)
return data
return crud.get_data(db, city=city, skip=skip, limit=limit)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_data refactored with the following changes:

Comment thread coronavirus/main.py
Comment on lines -72 to +69
if 200 == city_data.status_code:
if city_data.status_code == 200:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function bg_task refactored with the following changes:

Comment thread tutorial/chapter06.py
user = UserInDB(**user_dict)
hashed_password = fake_hash_password(form_data.password)
if not hashed_password == user.hashed_password:
if hashed_password != user.hashed_password:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function login refactored with the following changes:

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

Comment thread tutorial/chapter06.py
def fake_decode_token(token: str):
user = get_user(fake_users_db, token)
return user
return get_user(fake_users_db, token)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function fake_decode_token refactored with the following changes:

Comment thread tutorial/chapter06.py
Comment on lines -91 to -98
user = fake_decode_token(token)
if not user:
if user := fake_decode_token(token):
return user
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication credentials",
headers={"WWW-Authenticate": "Bearer"}, # OAuth2的规范,如果认证失败,请求头中返回“WWW-Authenticate”
)
return user
Copy link
Copy Markdown
Author

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:

Comment thread tutorial/chapter06.py
Comment on lines -152 to -157
user = jwt_get_user(db=db, username=username)
if not user:
return False
if not verity_password(plain_password=password, hashed_password=user.hashed_password):
if user := jwt_get_user(db=db, username=username):
return (
False
if not verity_password(
plain_password=password, hashed_password=user.hashed_password
)
else user
)
else:
return False
return user
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function jwt_authenticate_user refactored with the following changes:

Comment thread tutorial/chapter06.py
Comment on lines -166 to +170
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(claims=to_encode, key=SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
to_encode["exp"] = expire
return jwt.encode(claims=to_encode, key=SECRET_KEY, algorithm=ALGORITHM)
Copy link
Copy Markdown
Author

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:

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.

0 participants