From 5d85326ad8e2e8f780979617f1387a1fd8d9a0f4 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 13 Nov 2018 02:04:12 -0800 Subject: [PATCH] Expand Python 2's urllib.addbase definition. (#2601) Give it enough information to determine that addinfourl is iterable and that iteration and read methods return bytes. Modeled after what is in stdlib/3/urllib/response.pyi after confirming by looking at Python 2.7 stdlib code. --- stdlib/2/urllib.pyi | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/stdlib/2/urllib.pyi b/stdlib/2/urllib.pyi index fde604f29..12836231c 100644 --- a/stdlib/2/urllib.pyi +++ b/stdlib/2/urllib.pyi @@ -1,4 +1,4 @@ -from typing import Any, AnyStr, IO, Mapping, Sequence, Text, Tuple, Union +from typing import Any, AnyStr, IO, List, Mapping, Sequence, Text, Tuple, TypeVar, Union def url2pathname(pathname: str) -> str: ... def pathname2url(pathname: str) -> str: ... @@ -77,16 +77,18 @@ class ftpwrapper: def file_close(self): ... def real_close(self): ... +_AIUT = TypeVar("_AIUT", bound=addbase) + class addbase: fp = ... # type: Any - read = ... # type: Any - readline = ... # type: Any - readlines = ... # type: Any - fileno = ... # type: Any - __iter__ = ... # type: Any - next = ... # type: Any + def read(self, n: int = ...) -> bytes: ... + def readline(self, limit: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def fileno(self) -> int: ... # Optional[int], but that is rare + def __iter__(self: _AIUT) -> _AIUT: ... + def next(self) -> bytes: ... def __init__(self, fp) -> None: ... - def close(self): ... + def close(self) -> None: ... class addclosehook(addbase): closehook = ... # type: Any