You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
repro.py:6: error: Argument 1 to "dump" of "TemplateStream" has incompatible type "TextIOWrapper"; expected "str | IO[bytes]" [arg-type]
Changing the open call to open("foo.txt", "wb") makes mypy happy as output is now an IO[bytes], but at runtime the call to dump fails:
> real_fp.writelines(iterable)
E TypeError: a bytes-like object is required, not 'str'
opt/bb/lib/python3.11/site-packages/jinja2/environment.py:1626: TypeError
(It shouldn't matter, but this is python 3.11, jinja2 3.1.4, and mypy 1.10.0.)
This PR changed the hint for dump from
IO
toIO[bytes]
: #1968However, I believe if
encoding
is not provided (or explicitlyNone
), this should beIO[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 anIO[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
:The text was updated successfully, but these errors were encountered: