From b306d7742cdc85d06f7fafc05f78e2399923dd14 Mon Sep 17 00:00:00 2001 From: Guo Ci Date: Sat, 29 Nov 2025 14:33:43 -0500 Subject: [PATCH 1/4] [stdlib] Make `http.cookies.Morsel` inherit a `TypedDict` docs: https://docs.python.org/3/library/http.cookies.html#http.cookies.Morsel.expires src: https://github.com/python/cpython/blob/77399436bfc87663f9058b749b6cb598bab273f9/Lib/http/cookies.py#L257-L268 --- stdlib/http/cookies.pyi | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index 4df12e3125d4..b2e3dc658fed 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -1,6 +1,7 @@ +import sys from collections.abc import Iterable, Mapping from types import GenericAlias -from typing import Any, Generic, TypeVar, overload +from typing import Any, Generic, TypedDict, TypeVar, overload, type_check_only from typing_extensions import TypeAlias __all__ = ["CookieError", "BaseCookie", "SimpleCookie"] @@ -19,7 +20,22 @@ def _unquote(str: str) -> str: ... class CookieError(Exception): ... -class Morsel(dict[str, Any], Generic[_T]): +@type_check_only +class _MorselDictType(TypedDict): + expires: Any + path: Any + comment: Any + domain: Any + max_age: Any + secure: Any + httponly: Any + version: Any + samesite: Any + if sys.version_info >= (3, 14): + partitioned: Any + + +class Morsel(_MorselDictType, Generic[_T]): @property def value(self) -> str: ... @property From d8238fe4390a15fdcfb28264896287f93de0667b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 29 Nov 2025 19:37:49 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/http/cookies.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index b2e3dc658fed..a886d1ff1edf 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -34,7 +34,6 @@ class _MorselDictType(TypedDict): if sys.version_info >= (3, 14): partitioned: Any - class Morsel(_MorselDictType, Generic[_T]): @property def value(self) -> str: ... From c69bc81e31833127ab5b6cf54a7693f3efedb2f5 Mon Sep 17 00:00:00 2001 From: Guo Ci Date: Sat, 29 Nov 2025 14:45:18 -0500 Subject: [PATCH 3/4] Update _MorselDictType for version compatibility Refactor _MorselDictType to conditionally include 'partitioned' field for Python 3.14 and above. --- stdlib/http/cookies.pyi | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index a886d1ff1edf..a3ca76905177 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -20,19 +20,32 @@ def _unquote(str: str) -> str: ... class CookieError(Exception): ... -@type_check_only -class _MorselDictType(TypedDict): - expires: Any - path: Any - comment: Any - domain: Any - max_age: Any - secure: Any - httponly: Any - version: Any - samesite: Any - if sys.version_info >= (3, 14): - partitioned: Any +if sys.version_info >= (3, 14): + @type_check_only + class _MorselDictType(TypedDict): + expires: Any + path: Any + comment: Any + domain: Any + max_age: Any + secure: Any + httponly: Any + version: Any + samesite: Any + partitioned: Any # New in version 3.14. +else: + @type_check_only + class _MorselDictType(TypedDict): + expires: Any + path: Any + comment: Any + domain: Any + max_age: Any + secure: Any + httponly: Any + version: Any + samesite: Any + class Morsel(_MorselDictType, Generic[_T]): @property From 92f4a45c34b5710795bde14014c46b29946717ea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 29 Nov 2025 19:47:23 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/http/cookies.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index a3ca76905177..14203dd1e010 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -32,7 +32,8 @@ if sys.version_info >= (3, 14): httponly: Any version: Any samesite: Any - partitioned: Any # New in version 3.14. + partitioned: Any # New in version 3.14. + else: @type_check_only class _MorselDictType(TypedDict): @@ -46,7 +47,6 @@ else: version: Any samesite: Any - class Morsel(_MorselDictType, Generic[_T]): @property def value(self) -> str: ...