Skip to content

Commit 384096d

Browse files
committed
fix up types
1 parent b4e03d5 commit 384096d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/idom/core/component.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AbstractComponent(abc.ABC):
3434
if not hasattr(abc.ABC, "__weakref__"):
3535
__slots__.append("__weakref__") # pragma: no cover
3636

37-
key: str
37+
key: Optional[Any]
3838

3939
@abc.abstractmethod
4040
def render(self) -> VdomDict:
@@ -44,7 +44,7 @@ def render(self) -> VdomDict:
4444
class Component(AbstractComponent):
4545
"""An object for rending component models."""
4646

47-
__slots__ = "_function", "_args", "_kwargs"
47+
__slots__ = "_func", "_args", "_kwargs"
4848

4949
def __init__(
5050
self,
@@ -54,14 +54,14 @@ def __init__(
5454
kwargs: Dict[str, Any],
5555
) -> None:
5656
self.key = key
57-
self._function = function
57+
self._func = function
5858
self._args = args
5959
self._kwargs = kwargs
6060
if key is not None:
6161
kwargs["key"] = key
6262

6363
def render(self) -> VdomDict:
64-
model = self._function(*self._args, **self._kwargs)
64+
model = self._func(*self._args, **self._kwargs)
6565
if isinstance(model, AbstractComponent):
6666
model = {"tagName": "div", "children": [model]}
6767
return model
@@ -70,14 +70,14 @@ def __eq__(self, other: Any) -> bool:
7070
return isinstance(other, Component) and other._func == self._func
7171

7272
def __repr__(self) -> str:
73-
sig = inspect.signature(self._function)
73+
sig = inspect.signature(self._func)
7474
try:
7575
args = sig.bind(*self._args, **self._kwargs).arguments
7676
except TypeError:
77-
return f"{self._function.__name__}(...)"
77+
return f"{self._func.__name__}(...)"
7878
else:
7979
items = ", ".join(f"{k}={v!r}" for k, v in args.items())
8080
if items:
81-
return f"{self._function.__name__}({hex_id(self)}, {items})"
81+
return f"{self._func.__name__}({hex_id(self)}, {items})"
8282
else:
83-
return f"{self._function.__name__}({hex_id(self)})"
83+
return f"{self._func.__name__}({hex_id(self)})"

src/idom/widgets/html.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from base64 import b64encode
2-
from typing import Any, Callable, Dict, Optional, Union
2+
from typing import Any, Callable, Dict, Optional, Union, overload
33

44
import idom
55
from idom.core.component import AbstractComponent, ComponentConstructor, component
@@ -166,6 +166,18 @@ def __init__(self) -> None:
166166
self.menuitem = make_vdom_constructor("menuitem")
167167
self.summary = make_vdom_constructor("summary")
168168

169+
@overload
170+
@staticmethod
171+
def __call__(
172+
tag: ComponentConstructor, *attributes_and_children: Any
173+
) -> AbstractComponent:
174+
...
175+
176+
@overload
177+
@staticmethod
178+
def __call__(tag: str, *attributes_and_children: Any) -> VdomDict:
179+
...
180+
169181
@staticmethod
170182
def __call__(
171183
tag: Union[str, ComponentConstructor],

0 commit comments

Comments
 (0)