Skip to content

Commit

Permalink
use generic bases for session (#5638)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Nov 13, 2024
2 parents 7b21d43 + f49dbfd commit 2eab96a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/flask/sessions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import collections.abc as c
import hashlib
import typing as t
from collections.abc import MutableMapping
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2eab96a

Please sign in to comment.