Skip to content

Commit

Permalink
Respect type stability in write_raw_html
Browse files Browse the repository at this point in the history
  • Loading branch information
jrycw committed Jan 15, 2025
1 parent 9f24c52 commit 93ab9e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 4 additions & 8 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,12 @@ def _dump_debug_screenshot(driver, path):

def write_raw_html(
gt: GT,
filename: str | Path | None = None,
filename: str | Path,
encoding: str = "utf-8",
newline: str | None = None,
make_page: bool = False,
all_important: bool = False,
) -> str | None:
) -> None:
"""
Write the table to an HTML file.
Expand All @@ -581,7 +581,6 @@ def write_raw_html(
A GT object.
filename
The name of the file to save the HTML. Can be a string or a `pathlib.Path` object.
If set to `None` (default), the output is returned as a string instead.
encoding
The encoding used when writing the file. Defaults to 'utf-8'.
newline
Expand All @@ -592,13 +591,10 @@ def write_raw_html(
If `filename` is `None` (default), returns the HTML output as a string. Otherwise, writes
the HTML to the specified file path and returns `None`.
"""
html_content = as_raw_html(gt, make_page=make_page, all_important=all_important)

if filename is None:
return html_content

import os

html_content = as_raw_html(gt, make_page=make_page, all_important=all_important)

newline = newline if newline is not None else os.linesep

with open(filename, "w", encoding=encoding, newline=newline) as f:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def test_create_temp_file_server():
thread.join()


def test_write_raw_html_default(gt_tbl):
assert as_raw_html(gt_tbl) == gt_tbl.write_raw_html()
def test_write_raw_html_raises(gt_tbl):
with pytest.raises(TypeError):
gt_tbl.write_raw_html() # `filename=` must be specified


def test_write_raw_html(gt_tbl):
Expand Down

0 comments on commit 93ab9e3

Please sign in to comment.