Skip to content

Commit

Permalink
Move types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekcyjna committed Oct 23, 2023
1 parent bb5d161 commit 60c7cf4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 6 additions & 0 deletions coreblocks/utils/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Mapping,
TypeVar,
runtime_checkable,
Union,
Any,
)
from enum import Enum
from amaranth import *
Expand All @@ -32,6 +34,10 @@
SignalBundle: TypeAlias = Signal | Record | View | Iterable["SignalBundle"] | Mapping[str, "SignalBundle"]
LayoutList = list[Tuple[str, ShapeLike | "LayoutList"]]

RecordIntDict: TypeAlias = Mapping[str, Union[int, "RecordIntDict"]]
RecordIntDictRet: TypeAlias = Mapping[str, Any] # full typing hard to work with
RecordValueDict: TypeAlias = Mapping[str, Union[ValueLike, "RecordValueDict"]]


class _ModuleBuilderDomainsLike(Protocol):
def __getattr__(self, name: str) -> _ModuleBuilderDomain:
Expand Down
2 changes: 1 addition & 1 deletion test/common/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from amaranth import *
from typing import TYPE_CHECKING
from transactron._utils import RecordValueDict, RecordIntDict
from coreblocks.utils._typing import RecordValueDict, RecordIntDict


if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion test/common/sugar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
from typing import Callable, Any, Optional
from .testbenchio import TestbenchIO, TestGen
from transactron._utils import RecordIntDict
from coreblocks.utils._typing import RecordIntDict


def def_method_mock(
Expand Down
3 changes: 2 additions & 1 deletion test/common/testbenchio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from typing import Any, Generator, TypeVar, Optional, Callable
from transactron.lib import AdapterBase
from transactron.core import ValueLike, SignalBundle
from transactron._utils import method_def_helper, RecordIntDictRet, RecordValueDict, RecordIntDict
from transactron._utils import method_def_helper
from coreblocks.utils._typing import RecordIntDictRet, RecordValueDict, RecordIntDict
from .functions import set_inputs, get_outputs

T = TypeVar("T")
Expand Down
10 changes: 3 additions & 7 deletions transactron/_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import itertools
import sys
from inspect import Parameter, signature
from typing import Callable, Iterable, Optional, TypeAlias, TypeVar, Mapping, Union, Any
from typing import Callable, Iterable, Optional, TypeAlias, TypeVar, Mapping
from amaranth import *
from coreblocks.utils._typing import LayoutLike, ValueLike
from coreblocks.utils._typing import LayoutLike, ShapeLike
from coreblocks.utils import OneHotSwitchDynamic

__all__ = [
Expand All @@ -17,10 +17,6 @@
"method_def_helper",
]

RecordIntDict = Mapping[str, Union[int, "RecordIntDict"]]
RecordIntDictRet = Mapping[str, Any] # full typing hard to work with
RecordValueDict = Mapping[str, Union[ValueLike, "RecordValueDict"]]


T = TypeVar("T")

Expand Down Expand Up @@ -156,7 +152,7 @@ def get_caller_class_name(default: Optional[str] = None) -> tuple[Optional[Elabo
raise RuntimeError("Not called from a method")


def data_layout(val: int) -> LayoutLike:
def data_layout(val: ShapeLike) -> LayoutLike:
return [("data", val)]


Expand Down

0 comments on commit 60c7cf4

Please sign in to comment.