Open
Description
This PR changed the hint for dump from IO
to IO[bytes]
: #1968
However, I believe if encoding
is not provided (or explicitly None
), this should be IO[str]
? I certainly get a runtime error (TypeError: a bytes-like object is required, not 'str'
) if I try to change my code to pass in an IO[bytes]
to satisfy mypy, while the code works fine at runtime if I just # type: ignore
the new mypy errors.
I believe the type hint needs to change to an @overload
:
@overload
def dump(
self,
fp: t.Union[str, t.IO[bytes]],
encoding: str,
errors: t.Optional[str] = "strict",
) -> None:
...
@overload
def dump(
self,
fp: t.Union[str, t.IO[str]],
encoding: None = None,
errors: t.Optional[str] = "strict",
) -> None:
...
Metadata
Metadata
Assignees
Labels
No labels
Activity