From f49dbfd3e451006a485e81ebce030495131c4454 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 13 Nov 2024 08:22:57 -0800 Subject: [PATCH] use generic bases for session --- src/flask/sessions.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/flask/sessions.py b/src/flask/sessions.py index c2e6a852cb..375de06574 100644 --- a/src/flask/sessions.py +++ b/src/flask/sessions.py @@ -1,5 +1,6 @@ from __future__ import annotations +import collections.abc as c import hashlib import typing as t from collections.abc import MutableMapping @@ -20,8 +21,7 @@ from .wrappers import Response -# TODO generic when Python > 3.8 -class SessionMixin(MutableMapping): # type: ignore[type-arg] +class SessionMixin(MutableMapping[str, t.Any]): """Expands a basic dictionary with session attributes.""" @property @@ -49,8 +49,7 @@ def permanent(self, value: bool) -> None: accessed = True -# TODO generic when Python > 3.8 -class SecureCookieSession(CallbackDict, SessionMixin): # type: ignore[type-arg] +class SecureCookieSession(CallbackDict[str, t.Any], SessionMixin): """Base class for sessions based on signed cookies. This session backend will set the :attr:`modified` and @@ -72,7 +71,10 @@ class SecureCookieSession(CallbackDict, SessionMixin): # type: ignore[type-arg] #: different users. accessed = False - def __init__(self, initial: t.Any = None) -> None: + def __init__( + self, + initial: c.Mapping[str, t.Any] | c.Iterable[tuple[str, t.Any]] | None = None, + ) -> None: def on_update(self: te.Self) -> None: self.modified = True self.accessed = True