From: Jacob Lifshay Date: Tue, 19 Mar 2019 21:53:44 +0000 (-0700) Subject: fix Record and Layout typing X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c6184554ff75cb7759d2fee33bdb137b8b7c5737;p=nmigen-type-annotations.git fix Record and Layout typing --- diff --git a/nmigen/hdl/rec.pyi b/nmigen/hdl/rec.pyi index 577a543..ef564a7 100644 --- a/nmigen/hdl/rec.pyi +++ b/nmigen/hdl/rec.pyi @@ -1,5 +1,5 @@ import enum -from typing import List, Union, Tuple, Any, Dict, Optional +from typing import List, Union, Tuple, Any, Dict, Optional, Generator from .ast import Signal, Value __all__ = ["Direction", "DIR_NONE", "DIR_FANOUT", @@ -17,58 +17,77 @@ DIR_FANOUT = Direction.FANOUT DIR_FANIN = Direction.FANIN # recursive types are not yet supported by mypy, manually recurse a few times -LayoutInputFields0 = List[Union[Tuple[str, - Union[int, - Tuple[int, bool], - Any]], - Tuple[str, - Union[int, - Tuple[int, bool]], - Direction]]] - -LayoutInputFields1 = List[Union[Tuple[str, - Union[int, - Tuple[int, bool], - LayoutInputFields0]], - Tuple[str, - Union[int, - Tuple[int, bool]], - Direction]]] - -LayoutInputFields2 = List[Union[Tuple[str, - Union[int, - Tuple[int, bool], - LayoutInputFields1]], - Tuple[str, - Union[int, - Tuple[int, bool]], - Direction]]] - -LayoutInputFields3 = List[Union[Tuple[str, - Union[int, - Tuple[int, bool], - LayoutInputFields2]], - Tuple[str, - Union[int, - Tuple[int, bool]], - Direction]]] - -LayoutInputFields = List[Union[Tuple[str, - Union[int, - Tuple[int, bool], - LayoutInputFields3]], - Tuple[str, - Union[int, - Tuple[int, bool]], - Direction]]] +LayoutInputFields0 = Union['Layout', + List[Union[Tuple[str, + Union[int, + Tuple[int, bool], + Any]], + Tuple[str, + Union[int, + Tuple[int, bool]], + Direction]]]] + +LayoutInputFields1 = Union['Layout', + List[Union[Tuple[str, + Union[int, + Tuple[int, bool], + LayoutInputFields0]], + Tuple[str, + Union[int, + Tuple[int, bool]], + Direction]]]] + +LayoutInputFields2 = Union['Layout', + List[Union[Tuple[str, + Union[int, + Tuple[int, bool], + LayoutInputFields1]], + Tuple[str, + Union[int, + Tuple[int, bool]], + Direction]]]] + +LayoutInputFields3 = Union['Layout', + List[Union[Tuple[str, + Union[int, + Tuple[int, bool], + LayoutInputFields2]], + Tuple[str, + Union[int, + Tuple[int, bool]], + Direction]]]] + +LayoutInputFields = Union['Layout', + List[Union[Tuple[str, + Union[int, + Tuple[int, bool], + LayoutInputFields3]], + Tuple[str, + Union[int, + Tuple[int, bool]], + Direction]]]] + +LayoutFieldShape = Union[int, Tuple[int, bool], 'Layout'] class Layout: - fields: Dict[str, Tuple[Union[int, Tuple[int, bool], 'Layout'], Direction]] + fields: Dict[str, Tuple[LayoutFieldShape, Direction]] + + @staticmethod + def wrap(obj: LayoutInputFields) -> 'Layout': + ... def __init__(self, fields: LayoutInputFields) -> None: ... + def __getitem__(self, name: str) -> Tuple[LayoutFieldShape, Direction]: + ... + + def __iter__(self) -> Generator[Tuple[str, LayoutFieldShape, Direction], + None, + None]: + ... + class Record(Value): layout: Layout