Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 10 additions & 15 deletions stdlib/http/cookies.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]): ...
9 changes: 5 additions & 4 deletions stubs/yt-dlp/yt_dlp/cookies.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...