diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index 0373eae8ab29..345fe46018d5 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -1,12 +1,10 @@ -from _typeshed import MaybeNone -from collections.abc import Iterable, Mapping +from _typeshed import MaybeNone, SupportsItems, SupportsKeysAndGetItem +from collections.abc import Container, Iterable from types import GenericAlias from typing import Any, Generic, TypeVar, overload -from typing_extensions import TypeAlias __all__ = ["CookieError", "BaseCookie", "SimpleCookie"] -_DataType: TypeAlias = str | Mapping[str, str | Morsel[Any]] _T = TypeVar("_T") @overload @@ -31,27 +29,24 @@ class Morsel(dict[str, Any], Generic[_T]): def set(self, key: str, val: str, coded_val: _T) -> None: ... def setdefault(self, key: str, val: str | None = None) -> str: ... # The dict update can also get a keywords argument so this is incompatible - @overload # type: ignore[override] - def update(self, values: Mapping[str, str]) -> None: ... - @overload - def update(self, values: Iterable[tuple[str, str]]) -> None: ... + def update(self, values: Iterable[tuple[str, str]] | SupportsKeysAndGetItem[str, str]) -> None: ... # type: ignore[override] def isReservedKey(self, K: str) -> bool: ... - def output(self, attrs: list[str] | None = None, header: str = "Set-Cookie:") -> str: ... + def output(self, attrs: Container[str] | None = None, header: str = "Set-Cookie:") -> str: ... __str__ = output - def js_output(self, attrs: list[str] | None = None) -> str: ... - def OutputString(self, attrs: list[str] | None = None) -> str: ... + def js_output(self, attrs: Container[str] | None = None) -> str: ... + def OutputString(self, attrs: Container[str] | None = None) -> str: ... def __eq__(self, morsel: object) -> bool: ... def __setitem__(self, K: str, V: Any) -> None: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... class BaseCookie(dict[str, Morsel[_T]], Generic[_T]): - def __init__(self, input: _DataType | None = None) -> None: ... + def __init__(self, input: str | SupportsItems[str, str | Morsel[Any]] | None = None) -> None: ... def value_decode(self, val: str) -> tuple[_T, str]: ... def value_encode(self, val: _T) -> tuple[_T, str]: ... - def output(self, attrs: list[str] | None = None, header: str = "Set-Cookie:", sep: str = "\r\n") -> str: ... + def output(self, attrs: Container[str] | None = None, header: str = "Set-Cookie:", sep: str = "\r\n") -> str: ... __str__ = output - def js_output(self, attrs: list[str] | None = None) -> str: ... - def load(self, rawdata: _DataType) -> None: ... + def js_output(self, attrs: Container[str] | None = None) -> str: ... + def load(self, rawdata: str | SupportsItems[str, str | Morsel[Any]]) -> None: ... def __setitem__(self, key: str, value: str | Morsel[_T]) -> None: ... class SimpleCookie(BaseCookie[str]): ... diff --git a/stubs/yt-dlp/yt_dlp/cookies.pyi b/stubs/yt-dlp/yt_dlp/cookies.pyi index ba407e4d2fb0..7acdeca4bba3 100644 --- a/stubs/yt-dlp/yt_dlp/cookies.pyi +++ b/stubs/yt-dlp/yt_dlp/cookies.pyi @@ -1,8 +1,9 @@ -from collections.abc import Collection, Iterator, KeysView +from _typeshed import SupportsItems +from collections.abc import Iterator, KeysView from enum import Enum from http.cookiejar import Cookie, CookiePolicy, MozillaCookieJar -from http.cookies import SimpleCookie -from typing import Final, TextIO, TypeVar +from http.cookies import Morsel, SimpleCookie +from typing import Any, Final, TextIO, TypeVar from . import _LoggerProtocol from .minicurses import MultilinePrinter @@ -101,4 +102,4 @@ class DataParser: def pbkdf2_sha1(password: bytes, salt: bytes, iterations: int, key_length: int) -> bytes: ... class LenientSimpleCookie(SimpleCookie): - def load(self, data: str | Collection[str]) -> None: ... + def load(self, data: str | SupportsItems[str, str | Morsel[Any]]) -> None: ...