Skip to content

Remove None from function signatures where possible #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gt_extras/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def gt_highlight_cols(
def gt_hulk_col_numeric(
gt: GT,
columns: SelectExpr = None,
palette: str | list[str] | None = "PRGn",
domain: list[str] | list[int] | list[float] | None = None,
palette: str | list[str] = "PRGn",
domain: list[int] | list[float] | None = None,
na_color: str | None = None,
alpha: int | float | None = None, # TODO: see note
reverse: bool = False,
Expand Down
20 changes: 11 additions & 9 deletions gt_extras/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def gt_hyperlink(text: str, url: str, new_tab: bool = True) -> int:
def with_tooltip(
label: str,
tooltip: str,
text_decoration_style: Literal["solid", "dotted"] | None = "dotted",
color: str | None = "blue",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Possibly worth revisiting. Many of the rest I feel good about, but this one feels like I might've taken this theme too far.

text_decoration_style: Literal["solid", "dotted", "none"] = "dotted",
color: str | Literal["none"] = "blue",
) -> str:
"""
Create HTML text with tooltip functionality for use in GT table cells.
Expand All @@ -58,11 +58,10 @@ def with_tooltip(

text_decoration_style
A string indicating the style of underline decoration. Options are `"solid"`,
`"dotted"`, or `None`. If nothing is provided, then `"dotted"` will be used as a default.
`"dotted"`, or "none".

color
A string indicating the text color. If `None`, no color styling is applied.
If nothing is provided, then `"blue"` will be used as a default.
A string indicating the text color. If "none", no color styling is applied.

Returns
-------
Expand All @@ -71,18 +70,21 @@ def with_tooltip(
"""

# Throw if `text_decoration_style` is not one of the allowed values
if text_decoration_style not in [None, "solid", "dotted"]:
raise ValueError("Text_decoration_style must be one of `None`, 'solid', or 'dotted'")
if text_decoration_style not in ["none", "solid", "dotted"]:
raise ValueError("Text_decoration_style must be one of 'none', 'solid', or 'dotted'")

if color is None:
raise ValueError("color must be a string or 'none', not None.")

style = "cursor: help; "

if text_decoration_style is not None:
if text_decoration_style != "none":
style += "text-decoration: underline; "
style += f"text-decoration-style: {text_decoration_style}; "
else:
style += "text-decoration: none; "

if color is not None:
if color != "none":
style += f"color: {color}; "

return f'<abbr style="{style}" title="{tooltip}">{label}</abbr>'
15 changes: 8 additions & 7 deletions gt_extras/icons.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this change on line 23 preferable?

Switching from this:

a11y: Literal["deco", "sem"] | None = "deco"

To this

a11y: Literal["deco", "sem", "none"] = "deco"

Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
def fa_icon_repeat(
name: str = "star",
repeats: int = 1,
fill: str | None = "black",
fill_opacity: int | str | None = 1,
fill: str = "black",
fill_opacity: int | str = 1,
stroke: str | None = None,
stroke_width: str | None = None,
stroke_opacity: int | str | None = None,
height: str | None = None,
width: str | None = None,
margin_left: str | None = "auto",
margin_right: str | None = "0.2em",
position: str | None = "relative",
margin_left: str = "auto",
margin_right: str = "0.2em",
position: str = "relative",
title: str | None = None,
a11y: Literal["deco", "sem"] | None = "deco",
a11y: Literal["deco", "sem", "none"] = "deco",
) -> str:
"""
Create repeated FontAwesome SVG icons as HTML.
Expand Down Expand Up @@ -75,7 +75,8 @@ def fa_icon_repeat(
The title (tooltip) for the icon.

a11y
Accessibility mode: `"deco"` for decorative, `"sem"` for semantic.
Accessibility mode: `"deco"` for decorative, `"sem"` for semantic, `"none"` will result in
no accessibility features.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion gt_extras/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

def gt_plt_bar(
gt: GT,
columns: SelectExpr | None = None,
columns: SelectExpr = None,
fill: str = "purple",
bar_height: int = 20,
height: int = 30,
Expand Down
19 changes: 15 additions & 4 deletions gt_extras/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,29 @@ def test_with_tooltip_underline_fail():
with_tooltip("1", "Number One", text_decoration_style="underline")


def test_with_tooltip_no_decoration():
result = with_tooltip("1", "Number One", text_decoration_style=None)
def test_with_tooltip_None_color_fail():
with pytest.raises(ValueError):
with_tooltip("1", "Number One", color=None)


def test_with_tooltip_underline_style_none():
result = with_tooltip("1", "Number One", text_decoration_style="none")
expected = '<abbr style="cursor: help; text-decoration: none; color: blue; " title="Number One">1</abbr>'
assert result == expected


def test_with_tooltip_no_color():
result = with_tooltip("1", "Number One", color=None)
def test_with_tooltip_color_none_pass():
result = with_tooltip("1", "Number One", color="none")
expected = '<abbr style="cursor: help; text-decoration: underline; text-decoration-style: dotted; " title="Number One">1</abbr>'
assert result == expected


def test_with_tooltip_custom_color():
result = with_tooltip("1", "Number One", color="red")
expected = '<abbr style="cursor: help; text-decoration: underline; text-decoration-style: dotted; color: red; " title="Number One">1</abbr>'
assert result == expected


def test_with_tooltip_in_table():
df = pd.DataFrame(
{
Expand Down
1 change: 0 additions & 1 deletion gt_extras/tests/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def test_theme_pff_fonts_snap(snapshot, mini_gt):
def test_theme_pff_dividers(mini_gt):
themed_gt = gt_theme_pff(gt=mini_gt, divider="num")
html = themed_gt.as_raw_html()
print(html)
assert "border-left: 2px solid lightgrey" in html


Expand Down
Loading