Skip to content

Commit 1aced2f

Browse files
committed
correct type annotations
1 parent 2de0491 commit 1aced2f

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_python_types(session: Session) -> None:
200200
install_requirements_file(session, "check-types")
201201
install_requirements_file(session, "pkg-deps")
202202
install_requirements_file(session, "pkg-extras")
203-
session.run("mypy", "--strict", "src/idom")
203+
session.run("mypy", "--show-error-codes", "--strict", "src/idom")
204204

205205

206206
@nox.session

src/idom/core/hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def _try_to_infer_closure_values(
541541
else:
542542
return None
543543
else:
544-
return cast("Sequence[Any] | None", values)
544+
return values
545545

546546

547547
def current_hook() -> LifeCycleHook:

src/idom/core/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _render_component(
234234
old_parent_model = parent.model.current
235235
old_parent_children = old_parent_model["children"]
236236
parent.model.current = {
237-
**old_parent_model,
237+
**old_parent_model, # type: ignore[misc]
238238
"children": [
239239
*old_parent_children[:index],
240240
new_state.model.current,

src/idom/core/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ComponentType(Protocol):
4444
This is used to see if two component instances share the same definition.
4545
"""
4646

47-
def render(self) -> VdomDict | ComponentType | None:
47+
def render(self) -> VdomDict | ComponentType | str | None:
4848
"""Render the component's view model."""
4949

5050
def should_render(self: _OwnType, new: _OwnType) -> bool:

src/idom/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def __repr__(self) -> str:
5656
return f"{type(self).__name__}({current})"
5757

5858

59-
def html_to_vdom(html: str, *transforms: _ModelTransform, strict: bool = True) -> VdomDict:
59+
def html_to_vdom(
60+
html: str, *transforms: _ModelTransform, strict: bool = True
61+
) -> VdomDict:
6062
"""Transform HTML into a DOM model. Unique keys can be provided to HTML elements
6163
using a ``key=...`` attribute within your HTML tag.
6264
@@ -82,7 +84,9 @@ def html_to_vdom(html: str, *transforms: _ModelTransform, strict: bool = True) -
8284
recover=not strict,
8385
)
8486
try:
85-
nodes: List = fragments_fromstring(html, no_leading_text=True, parser=parser)
87+
nodes: list[etree._Element] = fragments_fromstring(
88+
html, no_leading_text=True, parser=parser
89+
)
8690
except etree.XMLSyntaxError as e:
8791
if not strict:
8892
raise e # pragma: no cover
@@ -139,10 +143,11 @@ def _etree_to_vdom(
139143
attributes = dict(node.items())
140144
key = attributes.pop("key", None)
141145

146+
vdom: VdomDict
142147
if hasattr(idom.html, node.tag):
143148
vdom = getattr(idom.html, node.tag)(attributes, *children, key=key)
144149
else:
145-
vdom: VdomDict = {"tagName": node.tag}
150+
vdom = {"tagName": node.tag}
146151
if children:
147152
vdom["children"] = children
148153
if attributes:
@@ -160,7 +165,7 @@ def _etree_to_vdom(
160165
return vdom
161166

162167

163-
def _mutate_vdom(vdom: VdomDict):
168+
def _mutate_vdom(vdom: VdomDict) -> None:
164169
"""Performs any necessary mutations on the VDOM attributes to meet VDOM spec.
165170
166171
Currently, this function only transforms the ``style`` attribute into a dictionary whose keys are
@@ -216,5 +221,5 @@ def _hypen_to_camel_case(string: str) -> str:
216221
return first.lower() + remainder.title().replace("-", "")
217222

218223

219-
class HTMLParseError(etree.LxmlSyntaxError):
224+
class HTMLParseError(etree.LxmlSyntaxError): # type: ignore[misc]
220225
"""Raised when an HTML document cannot be parsed using strict parsing."""

0 commit comments

Comments
 (0)