pyjson5 icon indicating copy to clipboard operation
pyjson5 copied to clipboard

typing error in python 3.13

Open ggilley opened this issue 6 months ago • 2 comments

I'm getting a typing error (with pyright) in python 3.13 with this:

        with open(path, 'r', encoding='utf-8') as f:
            config_data = json5.load(f)

The error is

config.py:752:27 - error: Type of "load" is partially unknown
    Type of "load" is "(fp: IO[Unknown], *, encoding: str | None = None, cls: Any = None, object_hook: ((Mapping[str, Any]) -> Any) | None = None, parse_float: ((str) -> Any) | None = None, parse_int: ((str) -> Any) | None = None, parse_constant: ((str) -> Any) | None = None, strict: bool = True, object_pairs_hook: ((Iterable[Tuple[str, Any]]) -> Any) | None = None, allow_duplicate_keys: bool = True, consume_trailing: bool = True, start: int | None = None) -> Any" (reportUnknownMemberType)

I think it's related to typing.io being removed in python 3.13? (I just tried 3.12.9 -- same error)

If I change it to

def load(
    fp: IO[str],
    *,
    encoding: Optional[str] = None,
    ...

The error goes away. I'm not positive this is the right fix though :-)

ggilley avatar Jul 12 '25 20:07 ggilley

Never mind. it's a "strict" pyright check. I'll turn it off.

ggilley avatar Jul 12 '25 23:07 ggilley

Looks like it's something that can be fixed or improved, though. I'll reopen it. Thanks for reporting!

dpranke avatar Jul 17 '25 17:07 dpranke