From b27a0b80a994ab94d00e6ebc41ea4ace9e7bf661 Mon Sep 17 00:00:00 2001 From: dataflow-solutions-sk Date: Mon, 17 Aug 2026 16:34:48 +0200 Subject: [PATCH] Parameterize IO/str type hints in json5/lib.py - load()'s fp parameter is now typed Union[IO[str], IO[bytes]] instead of the bare, unparameterized IO, since load() supports both text-mode and binary-mode file objects (confirmed by tests/lib_test.py's test_encoding, which passes an io.BytesIO to json5.load()). - dump()'s fp parameter is typed IO[str] since it only ever writes str. - loads()/parse()'s s parameter is now typed Union[str, bytes] to match their existing runtime support for byte strings (they already decode bytes via an isinstance check), fixing a latent inconsistency that the load() fix would otherwise expose as a new mypy error. Fixes reportUnknownMemberType/partially-unknown-type complaints from pyright/mypy when calling json5.load(f). Type-annotation-only change; verified zero behavioral impact via full test suite and `python -m mypy json5`. --- json5/lib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json5/lib.py b/json5/lib.py index 1047d5b..28f85b6 100644 --- a/json5/lib.py +++ b/json5/lib.py @@ -71,7 +71,7 @@ class QuoteStyle(enum.Enum): def load( - fp: IO, + fp: Union[IO[str], IO[bytes]], *, encoding: Optional[str] = None, cls: Any = None, @@ -145,7 +145,7 @@ def load( def loads( - s: str, + s: Union[str, bytes], *, encoding: Optional[str] = None, cls: Any = None, @@ -207,7 +207,7 @@ def loads( def parse( - s: str, + s: Union[str, bytes], *, encoding: Optional[str] = None, cls: Any = None, @@ -388,7 +388,7 @@ def _walk_ast( def dump( obj: Any, - fp: IO, + fp: IO[str], *, skipkeys: bool = False, ensure_ascii: bool = True,