Skip to content

Return HtmlSheet from Window.new_html_sheet - #14

Merged
FichteFoll merged 2 commits into
SublimeText:mainfrom
rchl:fix/new-html-sheet-return
Nov 4, 2026
Merged

FichteFoll merged 2 commits into
SublimeText:mainfrom
rchl:fix/new-html-sheet-return

Conversation

@rchl

@rchl rchl commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Window.new_html_sheet() is typed to return Sheet, but it always returns an HtmlSheet. It returns make_sheet() of the ID that window_new_html_sheet hands back, and make_sheet() dispatches on the ID's low bits, which mark an HTML sheet. With Sheet, callers have to narrow before they can use HtmlSheet.set_contents():

sheet = window.new_html_sheet("Preview", "<p>Loading</p>")
assert isinstance(sheet, sublime.HtmlSheet)
sheet.set_contents("<p>Done</p>")

The API reference also shows → Sheet, but it reflects the same annotation as the reference source and has no separate Returns section to say otherwise. HtmlSheet is a subclass of Sheet, so narrowing the return type doesn't break existing callers.

This came up while moving LSP to this package (sublimelsp/LSP#3129). LSP's bundled stubs already return HtmlSheet, and helper packages rely on that, so switching to this package as it is would break their type checks.

The fix is a RETURNS override, with the regenerated stub. The new update_html_sheet test in tests/typing/check_sublime.py fails on main (expected "HtmlSheet" but received "Sheet") and passes with this change. The generator's --check, all four checkers, and ruff for both the stubs and the tools pass locally.

This targets main. It will need a backport to st-4200 as well; happy to open that once this is settled.

@FichteFoll
FichteFoll merged commit d9fa761 into SublimeText:main Nov 4, 2026
9 checks passed
FichteFoll pushed a commit that referenced this pull request Nov 5, 2026
`Window.new_html_sheet()` is typed to return `Sheet`, but it always returns an `HtmlSheet`. It returns `make_sheet()` of the ID that `window_new_html_sheet` hands back, and `make_sheet()` dispatches on the ID's low bits, which mark an HTML sheet. With `Sheet`, callers have to narrow before they can use `HtmlSheet.set_contents()`.
@rchl
rchl deleted the fix/new-html-sheet-return branch November 5, 2026 06:06
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.

2 participants