Skip to content

Commit c630bdc

Browse files
committed
misc typing improvements + fix ico path
1 parent 3782255 commit c630bdc

File tree

8 files changed

+69
-53
lines changed

8 files changed

+69
-53
lines changed

docs/source/_custom_js/package-lock.json

Lines changed: 4 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/_exts/custom_autosectionlabel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from fnmatch import fnmatch
8-
from typing import Any, Dict, cast
8+
from typing import Any, cast
99

1010
from docutils import nodes
1111
from docutils.nodes import Node
@@ -30,7 +30,6 @@ def get_node_depth(node: Node) -> int:
3030

3131
def register_sections_as_label(app: Sphinx, document: Node) -> None:
3232
docname = app.env.docname
33-
print(docname)
3433

3534
for pattern in app.config.autosectionlabel_skip_docs:
3635
if fnmatch(docname, pattern):
@@ -67,7 +66,7 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
6766
domain.labels[name] = docname, labelid, sectname
6867

6968

70-
def setup(app: Sphinx) -> Dict[str, Any]:
69+
def setup(app: Sphinx) -> dict[str, Any]:
7170
app.add_config_value("autosectionlabel_prefix_document", False, "env")
7271
app.add_config_value("autosectionlabel_maxdepth", None, "env")
7372
app.add_config_value("autosectionlabel_skip_docs", [], "env")
Lines changed: 45 additions & 0 deletions
Loading

src/idom/core/component.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import inspect
44
from functools import wraps
5-
from typing import Any, Callable, Dict, Optional, Tuple
5+
from typing import Any, Callable, Optional
66

77
from .types import ComponentType, VdomDict
88

@@ -41,8 +41,8 @@ def __init__(
4141
self,
4242
function: Callable[..., ComponentType | VdomDict | str | None],
4343
key: Optional[Any],
44-
args: Tuple[Any, ...],
45-
kwargs: Dict[str, Any],
44+
args: tuple[Any, ...],
45+
kwargs: dict[str, Any],
4646
sig: inspect.Signature,
4747
) -> None:
4848
self.key = key

src/idom/core/hooks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
Any,
99
Awaitable,
1010
Callable,
11-
Dict,
1211
Generic,
13-
List,
1412
NewType,
1513
Optional,
1614
Sequence,
@@ -625,7 +623,7 @@ def __init__(
625623
self._rendered_atleast_once = False
626624
self._current_state_index = 0
627625
self._state: Tuple[Any, ...] = ()
628-
self._event_effects: Dict[EffectType, List[Callable[[], None]]] = {
626+
self._event_effects: dict[EffectType, list[Callable[[], None]]] = {
629627
COMPONENT_DID_RENDER_EFFECT: [],
630628
LAYOUT_DID_RENDER_EFFECT: [],
631629
COMPONENT_WILL_UNMOUNT_EFFECT: [],

src/idom/core/layout.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
from typing import (
99
Any,
1010
Callable,
11-
Dict,
1211
Generic,
1312
Iterator,
14-
List,
1513
NamedTuple,
1614
NewType,
1715
Optional,
18-
Set,
19-
Tuple,
2016
TypeVar,
2117
cast,
2218
)
@@ -217,7 +213,7 @@ def _render_model_attributes(
217213
self,
218214
old_state: Optional[_ModelState],
219215
new_state: _ModelState,
220-
raw_model: Dict[str, Any],
216+
raw_model: dict[str, Any],
221217
) -> None:
222218
# extract event handlers from 'eventHandlers' and 'attributes'
223219
handlers_by_event: EventHandlerDict = raw_model.get("eventHandlers", {})
@@ -385,7 +381,7 @@ def _render_model_children_without_old_state(
385381
self,
386382
exit_stack: ExitStack,
387383
new_state: _ModelState,
388-
raw_children: List[Any],
384+
raw_children: list[Any],
389385
) -> None:
390386
child_type_key_tuples = list(_process_child_type_and_key(raw_children))
391387

@@ -412,7 +408,7 @@ def _render_model_children_without_old_state(
412408
else:
413409
new_state.append_child(child)
414410

415-
def _unmount_model_states(self, old_states: List[_ModelState]) -> None:
411+
def _unmount_model_states(self, old_states: list[_ModelState]) -> None:
416412
to_unmount = old_states[::-1] # unmount in reversed order of rendering
417413
while to_unmount:
418414
model_state = to_unmount.pop()
@@ -561,8 +557,8 @@ def __init__(
561557
key: Any,
562558
model: Ref[VdomJson],
563559
patch_path: str,
564-
children_by_key: Dict[str, _ModelState],
565-
targets_by_event: Dict[str, str],
560+
children_by_key: dict[str, _ModelState],
561+
targets_by_event: dict[str, str],
566562
life_cycle_state: Optional[_LifeCycleState] = None,
567563
):
568564
self.index = index
@@ -661,7 +657,7 @@ class _ThreadSafeQueue(Generic[_Type]):
661657
def __init__(self) -> None:
662658
self._loop = asyncio.get_running_loop()
663659
self._queue: asyncio.Queue[_Type] = asyncio.Queue()
664-
self._pending: Set[_Type] = set()
660+
self._pending: set[_Type] = set()
665661

666662
def put(self, value: _Type) -> None:
667663
if value not in self._pending:
@@ -679,8 +675,8 @@ async def get(self) -> _Type:
679675

680676

681677
def _process_child_type_and_key(
682-
children: List[Any],
683-
) -> Iterator[Tuple[Any, _ElementType, Any]]:
678+
children: list[Any],
679+
) -> Iterator[tuple[Any, _ElementType, Any]]:
684680
for index, child in enumerate(children):
685681
if isinstance(child, dict):
686682
child_type = _DICT_TYPE

src/idom/core/types.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
TYPE_CHECKING,
88
Any,
99
Callable,
10-
Dict,
1110
Generic,
12-
Iterable,
13-
List,
1411
Mapping,
1512
NamedTuple,
1613
Optional,
@@ -20,7 +17,7 @@
2017
Union,
2118
)
2219

23-
from typing_extensions import Literal, Protocol, TypedDict, runtime_checkable
20+
from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, runtime_checkable
2421

2522

2623
_Type = TypeVar("_Type")
@@ -104,20 +101,13 @@ async def __aexit__(
104101
VdomChildren = Sequence[VdomChild]
105102
"""Describes a series of :class:`VdomChild` elements"""
106103

107-
VdomAttributesAndChildren = Union[
108-
Mapping[str, Any], # this describes both VdomDict and VdomAttributes
109-
Iterable[VdomChild],
110-
VdomChild,
111-
]
112-
"""Useful for the ``*attributes_and_children`` parameter in :func:`idom.core.vdom.vdom`"""
113-
114104

115105
class _VdomDictOptional(TypedDict, total=False):
116106
key: Key | None
117107
children: Sequence[
118108
# recursive types are not allowed yet:
119109
# https://github.com/python/mypy/issues/731
120-
Union[ComponentType, Dict[str, Any], str, Any]
110+
Union[ComponentType, dict[str, Any], str, Any]
121111
]
122112
attributes: VdomAttributes
123113
eventHandlers: EventHandlerDict # noqa
@@ -142,9 +132,9 @@ class ImportSourceDict(TypedDict):
142132
class _OptionalVdomJson(TypedDict, total=False):
143133
key: Key
144134
error: str
145-
children: List[Any]
146-
attributes: Dict[str, Any]
147-
eventHandlers: Dict[str, _JsonEventTarget] # noqa
135+
children: list[Any]
136+
attributes: dict[str, Any]
137+
eventHandlers: dict[str, _JsonEventTarget] # noqa
148138
importSource: _JsonImportSource # noqa
149139

150140

@@ -170,7 +160,7 @@ class _JsonImportSource(TypedDict):
170160
EventHandlerMapping = Mapping[str, "EventHandlerType"]
171161
"""A generic mapping between event names to their handlers"""
172162

173-
EventHandlerDict = Dict[str, "EventHandlerType"]
163+
EventHandlerDict: TypeAlias = "dict[str, EventHandlerType]"
174164
"""A dict mapping between event names to their handlers"""
175165

176166

src/idom/types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
RootComponentConstructor,
2121
State,
2222
VdomAttributes,
23-
VdomAttributesAndChildren,
2423
VdomChild,
2524
VdomChildren,
2625
VdomDict,
@@ -46,7 +45,6 @@
4645
"RootComponentConstructor",
4746
"State",
4847
"VdomAttributes",
49-
"VdomAttributesAndChildren",
5048
"VdomChild",
5149
"VdomChildren",
5250
"VdomDict",

0 commit comments

Comments
 (0)