Skip to content

Commit

Permalink
Merge pull request #15 from ar90n/feature/simplify-type-hints
Browse files Browse the repository at this point in the history
chore: Simplify type hints
  • Loading branch information
ar90n authored Apr 28, 2022
2 parents 7b4e936 + 197c6b4 commit 0d5581e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
10 changes: 5 additions & 5 deletions alfort/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import abstractmethod
from dataclasses import dataclass, replace
from itertools import zip_longest
from typing import Callable, Generic, List, Optional, Tuple, TypeAlias, TypeVar, Union
from typing import Callable, Generic, TypeAlias, TypeVar

from alfort.vdom import (
Element,
Expand All @@ -23,9 +23,9 @@

Dispatch: TypeAlias = Callable[[M], None]
Effect: TypeAlias = Callable[[Dispatch[M]], None]
View: TypeAlias = Callable[[S], Optional[VDom]]
Update: TypeAlias = Callable[[M, S], Tuple[S, List[Effect[M]]]]
Init: TypeAlias = Callable[[], Tuple[S, List[Effect[M]]]]
View: TypeAlias = Callable[[S], VDom | None]
Update: TypeAlias = Callable[[M, S], tuple[S, list[Effect[M]]]]
Init: TypeAlias = Callable[[], tuple[S, list[Effect[M]]]]
Mount: TypeAlias = Callable[[N], None]


Expand All @@ -40,7 +40,7 @@ class NodeDomText:
node: Node


NodeDom = Union[NodeDomElement, NodeDomText]
NodeDom = NodeDomElement | NodeDomText


class Alfort(Generic[S, M, N]):
Expand Down
19 changes: 5 additions & 14 deletions alfort/vdom.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from dataclasses import dataclass
from typing import (
Any,
Generic,
List,
MutableMapping,
Protocol,
TypeAlias,
TypeVar,
Union,
)
from typing import Any, Generic, MutableMapping, Protocol, TypeAlias, TypeVar

T = TypeVar("T")


@dataclass(slots=True, frozen=True)
class PatchProps:
remove_keys: List[str]
remove_keys: list[str]
add_props: "Props"


Expand All @@ -35,7 +26,7 @@ class PatchText:
value: str


Patch = Union[PatchProps, PatchInsertChild, PatchRemoveChild, PatchText]
Patch = PatchProps | PatchInsertChild | PatchRemoveChild | PatchText


class Node(Protocol):
Expand All @@ -47,15 +38,15 @@ def apply(self, patch: Patch) -> None:
class Element(Generic[T]):
tag: str
props: "Props"
children: List[T]
children: list[T]


@dataclass(slots=True, frozen=True)
class VDomElement(Element["VDom"]):
...


VDom = Union[VDomElement, str]
VDom = VDomElement | str


Props: TypeAlias = MutableMapping[str, Any]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Union
from typing import Any

import pytest

Expand Down Expand Up @@ -175,7 +175,7 @@ class CountDown:
value: int = 1


Msg = Union[CountUp, CountDown]
Msg = CountUp | CountDown


class TextNode(Node):
Expand Down

0 comments on commit 0d5581e

Please sign in to comment.