Skip to content

Instantly share code, notes, and snippets.

@egerlach
Created August 4, 2025 00:22
Show Gist options
  • Save egerlach/f47c9722794b5d03f832aada27da2293 to your computer and use it in GitHub Desktop.
Save egerlach/f47c9722794b5d03f832aada27da2293 to your computer and use it in GitHub Desktop.
Minimal test for typeshed reportlab issue
$ 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
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