Skip to content
Closed
Changes from 1 commit
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
Next Next commit
[stdlib] Make http.cookies.Morsel inherit a TypedDict
  • Loading branch information
guoci authored Nov 29, 2025
commit b306d7742cdc85d06f7fafc05f78e2399923dd14
20 changes: 18 additions & 2 deletions stdlib/http/cookies.pyi
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -19,22 +20,37 @@

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):

Check failure on line 34 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
partitioned: Any


class Morsel(_MorselDictType, Generic[_T]):
@property

Check failure on line 39 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def value(self) -> str: ...
@property

Check failure on line 41 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def coded_value(self) -> _T: ...
@property

Check failure on line 43 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def key(self) -> str: ...
def __init__(self) -> None: ...

Check failure on line 45 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def set(self, key: str, val: str, coded_val: _T) -> None: ...

Check failure on line 46 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def setdefault(self, key: str, val: str | None = None) -> str: ...

Check failure on line 47 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
# The dict update can also get a keywords argument so this is incompatible
@overload # type: ignore[override]

Check failure on line 49 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def update(self, values: Mapping[str, str]) -> None: ...
@overload

Check failure on line 51 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def update(self, values: Iterable[tuple[str, str]]) -> None: ...
def isReservedKey(self, K: str) -> bool: ...

Check failure on line 53 in stdlib/http/cookies.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

TypedDict classes can contain only type annotations (reportGeneralTypeIssues)
def output(self, attrs: list[str] | None = None, header: str = "Set-Cookie:") -> str: ...
__str__ = output
def js_output(self, attrs: list[str] | None = None) -> str: ...
Expand Down
Loading