Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use generic bases for session #5638

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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