Skip to content

Commit 43f16e8

Browse files
authored
fix type hint error for method (#395)
1 parent b994308 commit 43f16e8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/kirin/ir/attrs/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,5 +547,8 @@ def hint2type(hint) -> TypeAttribute:
547547
args = typing.get_args(hint)
548548
params = []
549549
for arg in args:
550-
params.append(hint2type(arg))
550+
if isinstance(arg, typing.Sequence):
551+
params.append([hint2type(elem) for elem in arg])
552+
else:
553+
params.append(hint2type(arg))
551554
return Generic(body, *params)

src/kirin/lowering/python/glob.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,6 @@ def visit_Call(self, node: ast.Call) -> Any:
100100

101101
def visit_Tuple(self, node: ast.Tuple) -> Any:
102102
return tuple(self.visit(elt) for elt in node.elts)
103+
104+
def visit_List(self, node: ast.List) -> Any:
105+
return [self.visit(elt) for elt in node.elts]

test/lowering/test_method_hint.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from kirin import ir, types
2+
from kirin.prelude import basic
3+
4+
5+
def test_method_type_hint():
6+
@basic
7+
def main() -> ir.Method[[int, int], float]:
8+
9+
def test(x: int, y: int) -> float:
10+
return x * y * 3.0
11+
12+
return test
13+
14+
assert main.return_type == types.Generic(
15+
ir.Method, [types.Int, types.Int], types.Float
16+
)

0 commit comments

Comments
 (0)