Skip to content

fix: restore import on Python 3.10-3.13 - #6

Merged
leonardosalasd merged 3 commits into
mainfrom
fix/v1.1.1-python-compat
Jul 31, 2026
Merged

fix: restore import on Python 3.10-3.13#6
leonardosalasd merged 3 commits into
mainfrom
fix/v1.1.1-python-compat

Conversation

@leonardosalasd

Copy link
Copy Markdown
Owner

Installing 1.1.0 and running any command raised, before doing any work:

TypeError: 'function' object is not subscriptable

mistune resolves tokens to renderer methods by name, so TypstRenderer has to
define one called list, which shadows the builtin inside the class body. The
tokens: list[dict] annotation added to load_footnotes in 1.1.0 was then
evaluated against that method while the class was being created. Python 3.14
defers annotation evaluation, which is why this never surfaced in development;
every supported version below it failed on import. Adding
from __future__ import annotations keeps annotations unevaluated everywhere.

Two more source-level fixes, both reachable from ordinary Markdown:

Square brackets now escape to \[ and \]. Typst reads a bare ] as a
stray closing delimiter, so a line like "close it with ] here" aborted the
compile. The citation pattern moves to _CITATION and matches the escaped
form so [@key] still resolves against a bibliography.

A leading --- block is only treated as front matter when it actually holds
key/value pairs. A document opening with a horizontal rule previously had
everything up to the next --- silently dropped from the PDF.

Covered by regression tests for each, verified on 3.10 through 3.14.

Installing 1.1.0 and running any command raised, before doing any work:

    TypeError: 'function' object is not subscriptable

mistune resolves tokens to renderer methods by name, so TypstRenderer has to
define one called `list`, which shadows the builtin inside the class body. The
`tokens: list[dict]` annotation added to `load_footnotes` in 1.1.0 was then
evaluated against that method while the class was being created. Python 3.14
defers annotation evaluation, which is why this never surfaced in development;
every supported version below it failed on import. Adding
`from __future__ import annotations` keeps annotations unevaluated everywhere.

Two more source-level fixes, both reachable from ordinary Markdown:

Square brackets now escape to `\[` and `\]`. Typst reads a bare `]` as a
stray closing delimiter, so a line like "close it with ] here" aborted the
compile. The citation pattern moves to `_CITATION` and matches the escaped
form so `[@key]` still resolves against a bibliography.

A leading `---` block is only treated as front matter when it actually holds
key/value pairs. A document opening with a horizontal rule previously had
everything up to the next `---` silently dropped from the PDF.

Covered by regression tests for each, verified on 3.10 through 3.14.
The 1.1.0 import crash shipped because the only environment it ever ran in
was Python 3.14, where deferred annotations hid it. Two jobs now guard that:
the suite runs on every supported version and platform, and a smoke job
installs the built package and drives the CLI from a clean directory, which
is the exact path that failed for users.
Route reviews to the repository owner, note math expressions and Mermaid
diagrams on the roadmap after user requests, and advertise Python 3.14 now
that it is covered by CI.

@leonardosalasd leonardosalasd left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@leonardosalasd
leonardosalasd merged commit ed73c00 into main Jul 31, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant