fix: update type annotations in csrf.py to pass mypy checks

This commit is contained in:
juan lainez 2024-05-30 13:21:23 -05:00
parent 5e52e26971
commit 57e40f0bfa
1 changed files with 5 additions and 10 deletions

View File

@ -2,8 +2,7 @@ import functools
import http.cookies
import secrets
from re import Pattern
from typing import Any, Callable, Coroutine, Dict, List, Optional, Set, cast
from typing import Dict, List, Optional, Set, Any, cast, Callable, Coroutine
from itsdangerous import BadSignature
from itsdangerous.url_safe import URLSafeSerializer
from starlette.datastructures import URL, MutableHeaders
@ -137,7 +136,7 @@ class CSRFMiddleware:
return cast(str, csrf_token)
def _generate_csrf_token(self) -> str:
token = self.serializer.dumps(secrets.token_urlsafe(128))
token = self.serializer.dumps(secrets.token_urlsafe(128))
return cast(str, token)
def _csrf_tokens_match(self, token1: str, token2: str) -> bool:
@ -153,12 +152,9 @@ class CSRFMiddleware:
content="CSRF token verification failed", status_code=403
)
def _receive_with_body(
self, receive: Any, body: bytes
) -> Callable[[], Coroutine[Any, Any, Dict[str, Any]]]:
async def inner() -> dict:
def _receive_with_body(self, receive: Any, body: bytes) -> Callable[[], Coroutine[Any, Any, Dict[str, Any]]]:
async def inner() -> dict :
return {"type": "http.request", "body": body, "more_body": False}
return inner
@ -174,5 +170,4 @@ def csrf_token_processor(csrf_cookie_name: str, csrf_header_name: str):
"csrf_input": csrf_input,
"csrf_header": csrf_header,
}
return processor
return processor