Skip to content

Commit 9d663fb

Browse files
authored
chore: Add types and check action for py-htmltools (#1692)
1 parent 19d711b commit 9d663fb

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

.github/py-shiny/check/action.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 'check py-shiny'
2+
description: 'Action that checks py-shiny in multiple steps so that any of them may fail but not prevent the others from running. Note, this action is used by py-htmltools as a way to consistently check py-shiny. If more checks are needed for py-htmltools to believe py-shiny is working, it should be added here.'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Run unit tests
7+
shell: bash
8+
run: |
9+
# Run unit tests
10+
make check-tests
11+
12+
- name: Type check
13+
shell: bash
14+
run: |
15+
# Type check
16+
make check-types
17+
18+
- name: Lint code
19+
shell: bash
20+
run: |
21+
# Lint code
22+
make check-lint
23+
24+
- name: Verify code formatting
25+
shell: bash
26+
run: |
27+
# Verify code formatting
28+
make check-format
29+
30+
- name: Verify code can run with mypy (not Windows)
31+
if: ${{ runner.os != 'Windows' }}
32+
shell: bash
33+
run: |
34+
# Verify code can run with mypy (not Windows)
35+
make ci-check-mypy-can-run

shiny/ui/_navs.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
from __future__ import annotations
22

3-
__all__ = (
4-
"nav_panel",
5-
"nav_menu",
6-
"nav_control",
7-
"nav_spacer",
8-
"navset_tab",
9-
"navset_card_tab",
10-
"navset_pill",
11-
"navset_underline",
12-
"navset_card_pill",
13-
"navset_card_underline",
14-
"navset_pill_list",
15-
"navset_hidden",
16-
"navset_bar",
17-
)
18-
193
import collections.abc
204
import copy
215
import re
226
from typing import Any, Literal, Optional, Sequence, cast
237

24-
from htmltools import MetadataNode, Tag, TagAttrs, TagChild, TagList, css, div, tags
8+
from htmltools import (
9+
HTML,
10+
MetadataNode,
11+
Tag,
12+
TagAttrs,
13+
TagChild,
14+
TagList,
15+
css,
16+
div,
17+
tags,
18+
)
2519

2620
from .._docstring import add_example
2721
from .._namespaces import resolve_id_or_none
@@ -34,6 +28,22 @@
3428
from .css import CssUnit, as_css_padding, as_css_unit
3529
from .fill import as_fill_item, as_fillable_container
3630

31+
__all__ = (
32+
"nav_panel",
33+
"nav_menu",
34+
"nav_control",
35+
"nav_spacer",
36+
"navset_tab",
37+
"navset_card_tab",
38+
"navset_pill",
39+
"navset_underline",
40+
"navset_card_pill",
41+
"navset_card_underline",
42+
"navset_pill_list",
43+
"navset_hidden",
44+
"navset_bar",
45+
)
46+
3747

3848
# -----------------------------------------------------------------------------
3949
# Navigation items
@@ -81,7 +91,7 @@ def resolve(
8191

8292
return nav, content
8393

84-
def get_value(self) -> Optional[str]:
94+
def get_value(self) -> str | HTML | None:
8595
if self.content is None:
8696
return None
8797
a_tag = cast(Tag, self.nav.children[0])

tests/pytest/test_modules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import cast
77

88
import pytest
9-
from htmltools import Tag, TagList
9+
from htmltools import HTML, Tag, TagList
1010

1111
from shiny import App, Inputs, Outputs, Session, module, reactive, ui
1212
from shiny._connection import MockConnection
@@ -28,7 +28,7 @@ def mod_outer_ui() -> TagList:
2828
return TagList(mod_inner_ui("inner"), ui.output_text("out2"))
2929

3030

31-
def get_id(x: TagList, child_idx: int = 0) -> str:
31+
def get_id(x: TagList, child_idx: int = 0) -> str | HTML:
3232
return cast(Tag, x[child_idx]).attrs["id"]
3333

3434

@@ -44,7 +44,7 @@ def test_module_ui():
4444

4545
@pytest.mark.asyncio
4646
async def test_session_scoping():
47-
sessions: dict[str, Session | str | None] = {}
47+
sessions: dict[str, Session | str | HTML | None] = {}
4848

4949
@module.server
5050
def inner_server(input: Inputs, output: Outputs, session: Session):

0 commit comments

Comments
 (0)