From 9abf620500644509a0ba656767e858ac2ef23dd6 Mon Sep 17 00:00:00 2001 From: Tim Stumbaugh Date: Mon, 24 Apr 2023 21:45:50 -0600 Subject: [PATCH] Loosen constraints on ujson file functions (#10081) Like `json.dump`, `ujson.dump` takes any object that has a string-accepting `.write` method. Similarly, `ujson.load` works with any object with a `.read()` that returns either a string or a bytes --- stubs/ujson/ujson.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/ujson/ujson.pyi b/stubs/ujson/ujson.pyi index 9f2155415..9c6ebf189 100644 --- a/stubs/ujson/ujson.pyi +++ b/stubs/ujson/ujson.pyi @@ -1,6 +1,6 @@ -from _typeshed import Incomplete +from _typeshed import Incomplete, SupportsRead, SupportsWrite from collections.abc import Callable -from typing import IO, Any, AnyStr +from typing import Any, AnyStr __version__: str @@ -32,7 +32,7 @@ def dumps( ) -> str: ... def dump( obj: Any, - fp: IO[str], + fp: SupportsWrite[str], *, ensure_ascii: bool = ..., double_precision: int = ..., @@ -47,6 +47,6 @@ def dump( ) -> None: ... def decode(s: AnyStr, precise_float: bool = ...) -> Any: ... def loads(s: AnyStr, precise_float: bool = ...) -> Any: ... -def load(fp: IO[AnyStr], precise_float: bool = ...) -> Any: ... +def load(fp: SupportsRead[str | bytes], precise_float: bool = ...) -> Any: ... class JSONDecodeError(ValueError): ...