Code Expression (#1) (#767)

* Replace unused `for` index with underscore

* Use `items()` to directly unpack dictionary values

* Merge duplicate blocks in conditional

* Use `any()` instead of for loop

* Format __init__.py
This commit is contained in:
Yasser Tahiri
2021-10-16 08:29:34 +01:00
committed by GitHub
parent 843b197875
commit 872b85de03
4 changed files with 13 additions and 13 deletions

View File

@ -152,11 +152,10 @@ class Authenticator:
if active and not user.is_active:
status_code = status.HTTP_401_UNAUTHORIZED
user = None
elif verified and not user.is_verified:
elif (
verified and not user.is_verified or superuser and not user.is_superuser
):
user = None
elif superuser and not user.is_superuser:
user = None
if not user and not optional:
raise HTTPException(status_code=status_code)
return user

View File

@ -307,7 +307,10 @@ class BaseUserManager(Generic[models.UC, models.UD]):
if not user.is_active:
raise UserInactive()
token_data = {"user_id": str(user.id), "aud": self.reset_password_token_audience}
token_data = {
"user_id": str(user.id),
"aud": self.reset_password_token_audience,
}
token = generate_jwt(
token_data,
self.reset_password_token_secret,
@ -535,8 +538,7 @@ class BaseUserManager(Generic[models.UC, models.UD]):
return user
async def _update(self, user: models.UD, update_dict: Dict[str, Any]) -> models.UD:
for field in update_dict:
value = update_dict[field]
for field, value in update_dict.items():
if field == "email" and value != user.email:
try:
await self.get_by_email(value)

View File

@ -50,11 +50,10 @@ def get_oauth_router(
scopes: List[str] = Query(None),
):
# Check that authentication_backend exists
backend_exists = False
for backend in authenticator.backends:
if backend.name == authentication_backend:
backend_exists = True
break
backend_exists = any(
backend.name == authentication_backend for backend in authenticator.backends
)
if not backend_exists:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)

View File

@ -137,5 +137,5 @@ async def test_authenticator_none_enabled(get_test_auth_client, user):
@pytest.mark.asyncio
async def test_authenticators_with_same_name(get_test_auth_client):
with pytest.raises(DuplicateBackendNamesError):
async for client in get_test_auth_client([BackendNone(), BackendNone()]):
async for _ in get_test_auth_client([BackendNone(), BackendNone()]):
pass