-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Type annotation wrong on TemplateStream.dump? #1983
Comments
Hi @alicederyn - Can you include a minimally reproducible example? |
Sure! Take this for instance: from jinja2 import Environment, FileSystemLoader
def simple_repro() -> None:
environment = Environment(loader=FileSystemLoader("."))
with open("foo.txt", "w") as output:
environment.get_template("foo.txt.jinja").stream(person="Stefanie").dump(output) with the following in
This runs fine, but mypy complains that:
Changing the open call to
(It shouldn't matter, but this is python 3.11, jinja2 3.1.4, and mypy 1.10.0.) |
Would like to bring up that I observe the same issue. This code, in my opinion, is perfectly fine:
However, I get this mypy complaint:
|
Just a note on this, the suggested fix of using There is an issue with simply adding
Using
|
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: