Skip to content

Commit b780780

Browse files
committed
Fixed mypy
1 parent 78560b5 commit b780780

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

brood/actions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,8 @@ def create_user(
461461
if signature is not None:
462462
payload_json = base64.decodebytes(signature.encode()).decode("utf-8")
463463
payload = json.loads(payload_json)
464-
if not isinstance(MoonstreamRegistration, MoonstreamRegistration):
465-
# Mypy hell
466-
raise Exception()
467-
verified = verify(authorization_payload=payload, schema=MoonstreamRegistration)
464+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
465+
verified = verify(authorization_payload=payload, schema=moonstream_schema)
468466
if not verified:
469467
logger.info("Moonstream registration verification error")
470468
raise MoonstreamVerificationError()

brood/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def create_user_handler(
162162
)
163163
except MoonstreamVerificationError:
164164
raise HTTPException(status_code=400, detail="Invalid user signature")
165-
except Exception:
165+
except Exception as e:
166166
raise HTTPException(status_code=500)
167167

168168
if autogenerated_user:

brood/middleware.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
import json
33
import logging
4-
from typing import Any, Dict, Optional, Tuple, Union
4+
from typing import Any, Dict, Optional
55
from uuid import UUID
66

77
from fastapi import Depends, HTTPException, Request
@@ -13,7 +13,7 @@
1313
from web3login.auth import MoonstreamRegistration, to_checksum_address, verify
1414
from web3login.exceptions import MoonstreamVerificationError
1515

16-
from . import actions, data, models
16+
from . import actions, data
1717
from .db import yield_db_read_only_session
1818
from .settings import BOT_INSTALLATION_TOKEN, BOT_INSTALLATION_TOKEN_HEADER
1919

@@ -85,11 +85,9 @@ async def get_current_user(
8585
if scheme == "moonstream":
8686
payload_json = base64.decodebytes(str(token).encode()).decode("utf-8")
8787
payload = json.loads(payload_json)
88-
if not isinstance(MoonstreamRegistration, MoonstreamRegistration):
89-
# Mypy hell
90-
raise HTTPException(status_code=500)
88+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
9189
verified = verify(
92-
authorization_payload=payload, schema=MoonstreamRegistration
90+
authorization_payload=payload, schema=moonstream_schema
9391
)
9492
if not verified:
9593
logger.info("Moonstream verification error")
@@ -162,12 +160,10 @@ async def get_current_user_with_groups(
162160
if scheme == "moonstream":
163161
payload_json = base64.decodebytes(str(token).encode()).decode("utf-8")
164162
payload = json.loads(payload_json)
165-
if not isinstance(MoonstreamRegistration, MoonstreamRegistration):
166-
# Mypy hell
167-
raise HTTPException(status_code=500)
163+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
168164
verified = verify(
169-
authorization_payload=payload, schema=MoonstreamRegistration
170-
)
165+
authorization_payload=payload, schema=moonstream_schema
166+
)
171167
if not verified:
172168
logger.info("Moonstream authorization verification error")
173169
raise MoonstreamVerificationError()

0 commit comments

Comments
 (0)