Created
August 4, 2025 00:22
-
-
Save egerlach/f47c9722794b5d03f832aada27da2293 to your computer and use it in GitHub Desktop.
Minimal test for typeshed reportlab issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python minimal_test.py | |
Test passed successfully | |
$ mypy minimal_test.py | |
minimal_test.py:13: error: Argument "filename" to "build" of "BaseDocTemplate" has incompatible type "BytesIO"; expected "str | None" [arg-type] | |
Found 1 error in 1 file (checked 1 source file)h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from pathlib import Path | |
from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, Paragraph | |
from reportlab.lib.units import inch | |
Path('test.pdf').unlink(True) | |
Path('not_test.pdf').unlink(True) | |
frame = Frame(2*inch, 2*inch, 5*inch, 5*inch) | |
template = PageTemplate(frames=[frame]) | |
doc = BaseDocTemplate("test.pdf", pageTemplates=[template]) | |
with io.BytesIO() as buffer: | |
doc.build([Paragraph("hello world")], filename=buffer) | |
with open("not_test.pdf", "wb") as f: | |
f.write(buffer.getvalue()) | |
# PDF written to not_test.pdf | |
assert not Path('test.pdf').exists(), "test.pdf should not be created" | |
assert Path('not_test.pdf').exists(), "not_test.pdf should be created" | |
Path('test.pdf').unlink(True) | |
Path('not_test.pdf').unlink(True) | |
print("Test passed successfully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment