Skip to content

Commit 40a980f

Browse files
authored
polish ilist wrapper (#218)
making the type hinting more precise cc: @kaihsin
1 parent 830adf2 commit 40a980f

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
1-
from typing import Any, TypeVar, Iterable
1+
from typing import TypeVar
22

33
from kirin import ir
44
from kirin.lowering import wraps
55

66
from . import stmts
77
from .runtime import IList
88

9-
T_Elem = TypeVar("T_Elem")
10-
T_Out = TypeVar("T_Out")
11-
T_Result = TypeVar("T_Result")
9+
ElemT = TypeVar("ElemT")
10+
OutElemT = TypeVar("OutElemT")
11+
LenT = TypeVar("LenT")
12+
ResultT = TypeVar("ResultT")
1213

1314

1415
@wraps(stmts.Map)
15-
def map(fn: ir.Method[[T_Elem], T_Out], collection: Iterable) -> IList | list: ...
16+
def map(
17+
fn: ir.Method[[ElemT], OutElemT], collection: IList[ElemT, LenT] | list[ElemT]
18+
) -> IList[OutElemT, LenT]: ...
1619

1720

1821
@wraps(stmts.Foldr)
1922
def foldr(
20-
fn: ir.Method[[T_Elem, T_Out], T_Out], collection: Iterable, init: T_Out
21-
) -> T_Out: ...
23+
fn: ir.Method[[ElemT, OutElemT], OutElemT],
24+
collection: IList[ElemT, LenT] | list[ElemT],
25+
init: OutElemT,
26+
) -> OutElemT: ...
2227

2328

2429
@wraps(stmts.Foldl)
2530
def foldl(
26-
fn: ir.Method[[T_Out, T_Elem], T_Out], collection: Iterable, init: T_Out
27-
) -> T_Out: ...
31+
fn: ir.Method[[OutElemT, ElemT], OutElemT],
32+
collection: IList[ElemT, LenT] | list[ElemT],
33+
init: OutElemT,
34+
) -> OutElemT: ...
2835

2936

3037
@wraps(stmts.Scan)
3138
def scan(
32-
fn: ir.Method[[T_Out, T_Elem], tuple[T_Out, T_Result]],
33-
collection: Iterable,
34-
init: T_Out,
35-
) -> tuple[T_Out, IList[T_Result, Any]]: ...
39+
fn: ir.Method[[OutElemT, ElemT], tuple[OutElemT, ResultT]],
40+
collection: IList[ElemT, LenT] | list[ElemT],
41+
init: OutElemT,
42+
) -> tuple[OutElemT, IList[ResultT, LenT]]: ...
3643

3744

3845
@wraps(stmts.ForEach)
39-
def for_each(fn: ir.Method[[T_Elem], None], collection: Iterable) -> None: ...
46+
def for_each(
47+
fn: ir.Method[[ElemT], None], collection: IList[ElemT, LenT] | list[ElemT]
48+
) -> None: ...

0 commit comments

Comments
 (0)