refactor: modernize typing annotations and simplify checks - #505
Merged
Conversation
Applies the same changes as PR #496 (originally opened by inquilabee's ShipGate tool, closed after its fork was deleted before it could be merged): switch typing.List/Dict/Tuple/Set to PEP 585 builtin generics now that the project targets Python 3.9+, and simplify a couple of emptiness/membership checks. Rebased onto the current 2.1.0+ code (the PR predated the font-size PX_TO_PT fix and the removal of the deprecated gradient-shape aliases).
…df_png
Traced to reportlab.graphics.renderPM._PMRenderer.drawImage, which reopens
a file-path <image> reference and calls PIL's Image.convert('RGB')
directly, without normalizing a palette+tRNS PNG to RGBA first like
svglib does for base64-embedded images. The rendered PNG is correct;
the warning is purely a reportlab-internal code path, so scope the
filter to this one test rather than changing image-handling behavior.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applies the same changes as #496 (originally opened by @inquilabee's ShipGate tool, closed after the source fork was deleted before it could be merged): switch
typing.List/Dict/Tuple/Setto PEP 585 builtin generics now that the project targets Python 3.9+, and simplify a couple of emptiness/membership checks. No behavior change.Rebased onto current
main— the original diff predated the font-sizePX_TO_PTfix (#503) and the removal of the deprecated gradient-shape aliases, so those spots were re-resolved by hand.Also includes an unrelated small fix: silences a
UserWarningfromtest_convert_pdf_pngthat traces to ReportLab's ownrenderPM.drawImage(it reopens a palette+tRNS PNG referenced by file path and converts it without normalizing first). The rendered PNG is correct; nothing to fix on svglib's side, so the warning is filtered with an explanatory docstring rather than changing image-handling behavior.Test plan
uv run pytest -q— 190 passed, 2 skipped, 1 xfailed, no warningsuv run ruff check ./uv run ruff format --check .— cleanuv run mypy src tests— clean