@@ -56,7 +56,9 @@ def __repr__(self) -> str:
56
56
return f"{ type (self ).__name__ } ({ current } )"
57
57
58
58
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 :
60
62
"""Transform HTML into a DOM model. Unique keys can be provided to HTML elements
61
63
using a ``key=...`` attribute within your HTML tag.
62
64
@@ -82,7 +84,9 @@ def html_to_vdom(html: str, *transforms: _ModelTransform, strict: bool = True) -
82
84
recover = not strict ,
83
85
)
84
86
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
+ )
86
90
except etree .XMLSyntaxError as e :
87
91
if not strict :
88
92
raise e # pragma: no cover
@@ -139,10 +143,11 @@ def _etree_to_vdom(
139
143
attributes = dict (node .items ())
140
144
key = attributes .pop ("key" , None )
141
145
146
+ vdom : VdomDict
142
147
if hasattr (idom .html , node .tag ):
143
148
vdom = getattr (idom .html , node .tag )(attributes , * children , key = key )
144
149
else :
145
- vdom : VdomDict = {"tagName" : node .tag }
150
+ vdom = {"tagName" : node .tag }
146
151
if children :
147
152
vdom ["children" ] = children
148
153
if attributes :
@@ -160,7 +165,7 @@ def _etree_to_vdom(
160
165
return vdom
161
166
162
167
163
- def _mutate_vdom (vdom : VdomDict ):
168
+ def _mutate_vdom (vdom : VdomDict ) -> None :
164
169
"""Performs any necessary mutations on the VDOM attributes to meet VDOM spec.
165
170
166
171
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:
216
221
return first .lower () + remainder .title ().replace ("-" , "" )
217
222
218
223
219
- class HTMLParseError (etree .LxmlSyntaxError ):
224
+ class HTMLParseError (etree .LxmlSyntaxError ): # type: ignore[misc]
220
225
"""Raised when an HTML document cannot be parsed using strict parsing."""
0 commit comments