Skip to content

Commit 602535f

Browse files
committed
rename proto modules to types
1 parent 1e11b22 commit 602535f

23 files changed

+82
-52
lines changed

src/idom/__init__.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from . import config, html, log, web
1+
from . import config, html, log, types, web
22
from .core import hooks
3-
from .core.component import Component, component
3+
from .core.component import component
44
from .core.dispatcher import Stop
5-
from .core.events import EventHandler, event
5+
from .core.events import event
66
from .core.hooks import (
77
create_context,
88
use_callback,
@@ -14,7 +14,6 @@
1414
use_state,
1515
)
1616
from .core.layout import Layout
17-
from .core.proto import ComponentType, VdomDict
1817
from .core.vdom import vdom
1918
from .sample import run_sample_app
2019
from .server.prefab import run
@@ -27,12 +26,9 @@
2726

2827
__all__ = [
2928
"component",
30-
"Component",
31-
"ComponentType",
3229
"config",
3330
"create_context",
3431
"event",
35-
"EventHandler",
3632
"hooks",
3733
"hotswap",
3834
"html_to_vdom",
@@ -44,6 +40,7 @@
4440
"run_sample_app",
4541
"run",
4642
"Stop",
43+
"types",
4744
"use_callback",
4845
"use_context",
4946
"use_effect",
@@ -52,6 +49,5 @@
5249
"use_ref",
5350
"use_state",
5451
"vdom",
55-
"VdomDict",
5652
"web",
5753
]

src/idom/core/component.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from functools import wraps
55
from typing import Any, Callable, Dict, Optional, Tuple, Union
66

7-
from .proto import ComponentType, VdomDict
7+
from .types import ComponentType, VdomDict
88

99

1010
def component(

src/idom/core/dispatcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from ._fixed_jsonpatch import apply_patch, make_patch # type: ignore
2626
from .layout import LayoutEvent, LayoutUpdate
27-
from .proto import LayoutType, VdomJson
27+
from .types import LayoutType, VdomJson
2828

2929

3030
logger = getLogger(__name__)

src/idom/core/events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from anyio import create_task_group
77
from typing_extensions import Literal
88

9-
from idom.core.proto import EventHandlerFunc, EventHandlerType
9+
from idom.core.types import EventHandlerFunc, EventHandlerType
1010

1111

1212
@overload

src/idom/core/hooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from idom.utils import Ref
2828

2929
from ._thread_local import ThreadLocal
30-
from .proto import Key, VdomDict
30+
from .types import Key, VdomDict
3131
from .vdom import vdom
3232

3333

src/idom/core/layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from ._event_proxy import _wrap_in_warning_event_proxies
3434
from .hooks import LifeCycleHook
35-
from .proto import ComponentType, EventHandlerDict, VdomDict, VdomJson
35+
from .types import ComponentType, EventHandlerDict, VdomDict, VdomJson
3636
from .vdom import validate_vdom_json
3737

3838

src/idom/core/proto.py renamed to src/idom/core/types.py

+12
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,15 @@ class EventHandlerType(Protocol):
180180
181181
When ``None``, it is left to a :class:`LayoutType` to auto generate a unique ID.
182182
"""
183+
184+
185+
class VdomDictConstructor(Protocol):
186+
"""Standard function for constructing a :class:`VdomDict`"""
187+
188+
def __call__(
189+
self,
190+
*attributes_and_children: VdomAttributesAndChildren,
191+
key: str = ...,
192+
event_handlers: Optional[EventHandlerMapping] = ...,
193+
) -> VdomDict:
194+
...

src/idom/core/vdom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
merge_event_handlers,
1414
to_event_handler_function,
1515
)
16-
from idom.core.proto import (
16+
from idom.core.types import (
1717
EventHandlerDict,
1818
EventHandlerMapping,
1919
EventHandlerType,
@@ -320,7 +320,7 @@ def _is_single_child(value: Any) -> bool:
320320
if _debug_is_single_child(value):
321321
return True
322322

323-
from .proto import ComponentType
323+
from .types import ComponentType
324324

325325
if hasattr(value, "__iter__") and not hasattr(value, "__len__"):
326326
logger.error(

src/idom/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160

161161
from typing import Any, Mapping
162162

163-
from .core.proto import Key, VdomDict
163+
from .core.types import Key, VdomDict
164164
from .core.vdom import coalesce_attributes_and_children, make_vdom_constructor
165165

166166

src/idom/sample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import webbrowser
44
from typing import Any
55

6-
from idom.server.proto import ServerType
6+
from idom.server.types import ServerType
77

88
from . import html
99
from .core.component import component
10-
from .core.proto import VdomDict
10+
from .core.types import VdomDict
1111
from .server.utils import find_available_port, find_builtin_server_type
1212

1313

src/idom/server/fastapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from fastapi import FastAPI
44

5-
from idom.core.proto import ComponentConstructor
5+
from idom.core.types import ComponentConstructor
66

77
from .starlette import (
88
Config,

src/idom/server/flask.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
2323
from idom.core.dispatcher import dispatch_single_view
2424
from idom.core.layout import LayoutEvent, LayoutUpdate
25-
from idom.core.proto import ComponentConstructor, ComponentType
25+
from idom.core.types import ComponentConstructor, ComponentType
2626

2727
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2828

src/idom/server/prefab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22
from typing import Any, Dict, Optional, Tuple, TypeVar
33

4-
from idom.core.proto import ComponentConstructor
4+
from idom.core.types import ComponentConstructor
55
from idom.widgets import MountFunc, MultiViewMount, hotswap, multiview
66

7-
from .proto import ServerFactory, ServerType
7+
from .types import ServerFactory, ServerType
88
from .utils import find_available_port, find_builtin_server_type
99

1010

src/idom/server/sanic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ensure_shared_view_dispatcher_future,
2424
)
2525
from idom.core.layout import Layout, LayoutEvent
26-
from idom.core.proto import ComponentConstructor
26+
from idom.core.types import ComponentConstructor
2727

2828
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2929

src/idom/server/starlette.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ensure_shared_view_dispatcher_future,
3131
)
3232
from idom.core.layout import Layout, LayoutEvent
33-
from idom.core.proto import ComponentConstructor
33+
from idom.core.types import ComponentConstructor
3434

3535
from .utils import CLIENT_BUILD_DIR, poll, threaded
3636

src/idom/server/tornado.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from idom.config import IDOM_WEB_MODULES_DIR
1717
from idom.core.dispatcher import VdomJsonPatch, dispatch_single_view
1818
from idom.core.layout import Layout, LayoutEvent
19-
from idom.core.proto import ComponentConstructor
19+
from idom.core.types import ComponentConstructor
2020

2121
from .utils import CLIENT_BUILD_DIR, threaded, wait_on_event
2222

src/idom/server/proto.py renamed to src/idom/server/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing_extensions import Protocol
77

8-
from idom.core.proto import ComponentConstructor
8+
from idom.core.types import ComponentConstructor
99

1010

1111
_App = TypeVar("_App")

src/idom/server/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import idom
1414

15-
from .proto import ServerFactory
15+
from .types import ServerFactory
1616

1717

1818
CLIENT_BUILD_DIR = Path(idom.__file__).parent / "client"

src/idom/testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from idom.core.events import EventHandler, to_event_handler_function
3535
from idom.core.hooks import LifeCycleHook, current_hook
3636
from idom.server.prefab import hotswap_server
37-
from idom.server.proto import ServerFactory, ServerType
37+
from idom.server.types import ServerFactory, ServerType
3838
from idom.server.utils import find_available_port
3939

4040
from .log import ROOT_LOGGER

src/idom/types.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from .core.types import (
2+
ComponentConstructor,
3+
ComponentType,
4+
EventHandlerDict,
5+
EventHandlerFunc,
6+
EventHandlerMapping,
7+
EventHandlerType,
8+
ImportSourceDict,
9+
Key,
10+
LayoutType,
11+
VdomAttributes,
12+
VdomAttributesAndChildren,
13+
VdomChild,
14+
VdomChildren,
15+
VdomDict,
16+
VdomJson,
17+
)
18+
from .server.types import ServerFactory, ServerType
19+
20+
21+
__all__ = [
22+
"ComponentConstructor",
23+
"ComponentType",
24+
"EventHandlerDict",
25+
"EventHandlerFunc",
26+
"EventHandlerMapping",
27+
"EventHandlerType",
28+
"ImportSourceDict",
29+
"Key",
30+
"LayoutType",
31+
"VdomAttributes",
32+
"VdomAttributesAndChildren",
33+
"VdomChild",
34+
"VdomChildren",
35+
"VdomDict",
36+
"VdomJson",
37+
"ServerFactory",
38+
"ServerType",
39+
]

src/idom/web/module.py

+5-22
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@
1010
from typing import Any, List, NewType, Optional, Set, Tuple, Union, overload
1111
from urllib.parse import urlparse
1212

13-
from typing_extensions import Protocol
14-
1513
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
16-
from idom.core.proto import (
17-
EventHandlerMapping,
18-
ImportSourceDict,
19-
VdomAttributesAndChildren,
20-
VdomDict,
21-
)
14+
from idom.core.types import ImportSourceDict, VdomDictConstructor
2215
from idom.core.vdom import make_vdom_constructor
2316

2417
from .utils import (
@@ -292,16 +285,6 @@ def module_from_string(
292285
)
293286

294287

295-
class _VdomDictConstructor(Protocol):
296-
def __call__(
297-
self,
298-
*attributes_and_children: VdomAttributesAndChildren,
299-
key: str = ...,
300-
event_handlers: Optional[EventHandlerMapping] = ...,
301-
) -> VdomDict:
302-
...
303-
304-
305288
@dataclass(frozen=True)
306289
class WebModule:
307290
source: str
@@ -318,7 +301,7 @@ def export(
318301
export_names: str,
319302
fallback: Optional[Any] = ...,
320303
allow_children: bool = ...,
321-
) -> _VdomDictConstructor:
304+
) -> VdomDictConstructor:
322305
...
323306

324307

@@ -328,7 +311,7 @@ def export(
328311
export_names: Union[List[str], Tuple[str, ...]],
329312
fallback: Optional[Any] = ...,
330313
allow_children: bool = ...,
331-
) -> List[_VdomDictConstructor]:
314+
) -> List[VdomDictConstructor]:
332315
...
333316

334317

@@ -337,7 +320,7 @@ def export(
337320
export_names: Union[str, List[str], Tuple[str, ...]],
338321
fallback: Optional[Any] = None,
339322
allow_children: bool = True,
340-
) -> Union[_VdomDictConstructor, List[_VdomDictConstructor]]:
323+
) -> Union[VdomDictConstructor, List[VdomDictConstructor]]:
341324
"""Return one or more VDOM constructors from a :class:`WebModule`
342325
343326
Parameters:
@@ -375,7 +358,7 @@ def _make_export(
375358
name: str,
376359
fallback: Optional[Any],
377360
allow_children: bool,
378-
) -> _VdomDictConstructor:
361+
) -> VdomDictConstructor:
379362
return partial(
380363
make_vdom_constructor(
381364
name,

src/idom/widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from . import html
2222
from .core import hooks
2323
from .core.component import component
24-
from .core.proto import ComponentConstructor, VdomDict
24+
from .core.types import ComponentConstructor, VdomDict
2525
from .utils import Ref
2626

2727

tests/test_core/test_vdom.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import idom
55
from idom.config import IDOM_DEBUG_MODE
66
from idom.core.events import EventHandler
7-
from idom.core.proto import VdomDict
7+
from idom.core.types import VdomDict
88
from idom.core.vdom import is_vdom, make_vdom_constructor, validate_vdom_json
99

1010

0 commit comments

Comments
 (0)