From 939be9a78713cbd7763cd2a16f902c494f5fe4d1 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 5 Mar 2019 12:14:00 -0800 Subject: [PATCH] Make 2.7's json.load use a protocol for fp (#2826) This matches what the 3 stub does --- stdlib/2/json.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 390810474..bd48dc548 100644 --- a/stdlib/2/json.pyi +++ b/stdlib/2/json.pyi @@ -1,4 +1,4 @@ -from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text +from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text, Protocol class JSONDecodeError(ValueError): def dumps(self, obj: Any) -> str: ... @@ -43,7 +43,10 @@ def loads(s: Union[Text, bytes], object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., **kwds: Any) -> Any: ... -def load(fp: IO[str], +class _Reader(Protocol): + def read(self) -> Union[Text, bytes]: ... + +def load(fp: _Reader, encoding: Optional[str] = ..., cls: Any = ..., object_hook: Optional[Callable[[Dict], Any]] = ...,