From f32a22701d0fe19d13d1daa8e5d010ce5ef36b9c Mon Sep 17 00:00:00 2001 From: Adam Bannister Date: Thu, 17 Oct 2019 22:00:36 +0200 Subject: [PATCH 1/3] add more types to LooseCookies #4205 --- aiohttp/cookiejar.py | 2 +- aiohttp/typedefs.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py index ac102bfc487..2d858de0e18 100644 --- a/aiohttp/cookiejar.py +++ b/aiohttp/cookiejar.py @@ -124,7 +124,7 @@ def update_cookies(self, return if isinstance(cookies, Mapping): - cookies = cookies.items() # type: ignore + cookies = cookies.items() for name, cookie in cookies: if not isinstance(cookie, Morsel): diff --git a/aiohttp/typedefs.py b/aiohttp/typedefs.py index 3c42f6abe30..278d8801e83 100644 --- a/aiohttp/typedefs.py +++ b/aiohttp/typedefs.py @@ -29,7 +29,7 @@ _CIMultiDictProxy = CIMultiDictProxy[str] _MultiDict = MultiDict[str] _MultiDictProxy = MultiDictProxy[str] - from http.cookies import BaseCookie # noqa + from http.cookies import BaseCookie, Morsel # noqa else: _CIMultiDict = CIMultiDict _CIMultiDictProxy = CIMultiDictProxy @@ -43,8 +43,13 @@ _CIMultiDictProxy] RawHeaders = Tuple[Tuple[bytes, bytes], ...] StrOrURL = Union[str, URL] -LooseCookies = Union[Iterable[Tuple[str, 'BaseCookie[str]']], - Mapping[str, 'BaseCookie[str]'], 'BaseCookie[str]'] +LooseCookies = Union[ + Iterable[Tuple[str, 'BaseCookie[str]']], + Iterable[Tuple[str, 'Morsel[Any]']], + Mapping[str, 'BaseCookie[str]'], + Mapping[str, 'Morsel[Any]'], + 'BaseCookie[str]', +] if sys.version_info >= (3, 6): From 87fed7ca608427beff3c02d858562bde0c3e86d4 Mon Sep 17 00:00:00 2001 From: Adam Bannister Date: Thu, 17 Oct 2019 22:45:26 +0200 Subject: [PATCH 2/3] predefine the Union types for LooseCookies --- aiohttp/typedefs.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/aiohttp/typedefs.py b/aiohttp/typedefs.py index 278d8801e83..d96f69d2e28 100644 --- a/aiohttp/typedefs.py +++ b/aiohttp/typedefs.py @@ -43,11 +43,16 @@ _CIMultiDictProxy] RawHeaders = Tuple[Tuple[bytes, bytes], ...] StrOrURL = Union[str, URL] + +StrBaseCookieTuples = Iterable[Tuple[str, 'BaseCookie[str]']] +StrMorselTuples = Iterable[Tuple[str, 'Morsel[str]']] +StrToBaseCookieMapping = Mapping[str, 'BaseCookie[str]'] +StrToMorselMapping = Mapping[str, 'Morsel[Any]'] LooseCookies = Union[ - Iterable[Tuple[str, 'BaseCookie[str]']], - Iterable[Tuple[str, 'Morsel[Any]']], - Mapping[str, 'BaseCookie[str]'], - Mapping[str, 'Morsel[Any]'], + StrBaseCookieTuples, + StrMorselTuples, + StrToBaseCookieMapping, + StrToMorselMapping, 'BaseCookie[str]', ] From e68171d947ba418e5c031655a9cc1fa2af7686c4 Mon Sep 17 00:00:00 2001 From: Adam Bannister Date: Thu, 17 Oct 2019 22:49:25 +0200 Subject: [PATCH 3/3] add CHANGES fragment --- CHANGES/4218.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/4218.misc diff --git a/CHANGES/4218.misc b/CHANGES/4218.misc new file mode 100644 index 00000000000..1cb60297f81 --- /dev/null +++ b/CHANGES/4218.misc @@ -0,0 +1 @@ +Add two more types to LooseCookies.