Skip to content

Commit 43091a5

Browse files
authored
fix some pyright errors (#367)
1 parent 5582a34 commit 43091a5

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

src/kirin/decl/scan_fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def _get_field(self, name: str, typ):
101101
return f
102102

103103
def _post_init_field(self, f: Field, guess: type | None):
104-
if isinstance(f, ArgumentField) and is_subhint(guess, tuple[ir.SSAValue, ...]):
104+
if isinstance(f, ArgumentField) and (
105+
guess and is_subhint(guess, tuple[ir.SSAValue, ...])
106+
):
105107
f.group = True
106108
# try to narrow the type based on the guess
107109
elif isinstance(f, AttributeField):

src/kirin/dialects/ilist/runtime.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@dataclass
14-
class IList(ir.Data[Sequence[T]], Generic[T, L]):
14+
class IList(ir.Data[Sequence[T]], Sequence[T], Generic[T, L]):
1515
"""A simple immutable list."""
1616

1717
data: Sequence[T]
@@ -63,22 +63,25 @@ def __iter__(self):
6363
return iter(self.data)
6464

6565
@overload
66-
def __getitem__(self, index: slice) -> "IList[T, Any]": ...
66+
def __getitem__(self, index: int) -> T: ...
6767

6868
@overload
69-
def __getitem__(self, index: int) -> T: ...
69+
def __getitem__(self, index: slice) -> "IList[T, Any]": ...
7070

7171
def __getitem__(self, index: int | slice) -> T | "IList[T, Any]":
7272
if isinstance(index, slice):
7373
return IList(self.data[index])
7474
return self.data[index]
7575

76+
def __contains__(self, item: object) -> bool:
77+
return item in self.data
78+
7679
def __eq__(self, value: object) -> bool:
7780
if not isinstance(value, IList):
7881
return False
7982
return self.data == value.data
8083

81-
def unwrap(self) -> "IList[T, L]":
84+
def unwrap(self) -> Sequence[T]:
8285
return self
8386

8487
def print_impl(self, printer: Printer) -> None:

src/kirin/dialects/py/assign.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def lower_AugAssign(
154154
rhs = ast.Attribute(obj, attr, ast.Load())
155155
case ast.Subscript(obj, slice, ast.Store()):
156156
rhs = ast.Subscript(obj, slice, ast.Load())
157+
case _:
158+
raise lowering.BuildError(f"unsupported target {node.target}")
157159
self.assign_item_value(
158160
state,
159161
node.target,

src/kirin/ir/traits/callable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def get_signature(cls, stmt: "Statement"):
4343
def set_signature(cls, stmt: "Statement", signature: "Signature"):
4444
stmt.attributes["signature"] = signature
4545

46-
def verify(self, stmt: "Statement"):
46+
def verify(self, node: "Statement"):
4747
from kirin.dialects.func.attrs import Signature
4848

49-
signature = self.get_signature(stmt)
49+
signature = self.get_signature(node)
5050
if not isinstance(signature, Signature):
5151
raise ValueError(f"{signature} is not a Signature attribute")

src/kirin/ir/traits/symbol.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def get_sym_name(self, stmt: Statement) -> PyAttr[str]:
2525
raise ValueError(f"Statement {stmt.name} does not have a symbol name")
2626
return sym_name
2727

28-
def verify(self, stmt: Statement):
28+
def verify(self, node: Statement):
2929
from kirin.types import String
3030

31-
sym_name = self.get_sym_name(stmt)
31+
sym_name = self.get_sym_name(node)
3232
if not (isinstance(sym_name, PyAttr) and sym_name.type.is_subseteq(String)):
3333
raise ValueError(f"Symbol name {sym_name} is not a string attribute")
3434

@@ -43,17 +43,17 @@ class SymbolTable(StmtTrait):
4343
def walk(stmt: Statement):
4444
return stmt.regions[0].blocks[0].stmts
4545

46-
def verify(self, stmt: Statement):
47-
if len(stmt.regions) != 1:
46+
def verify(self, node: Statement):
47+
if len(node.regions) != 1:
4848
raise ValidationError(
49-
stmt,
50-
f"Statement {stmt.name} with SymbolTable trait must have exactly one region",
49+
node,
50+
f"Statement {node.name} with SymbolTable trait must have exactly one region",
5151
)
5252

53-
if len(stmt.regions[0].blocks) != 1:
53+
if len(node.regions[0].blocks) != 1:
5454
raise ValidationError(
55-
stmt,
56-
f"Statement {stmt.name} with SymbolTable trait must have exactly one block",
55+
node,
56+
f"Statement {node.name} with SymbolTable trait must have exactly one block",
5757
)
5858

5959
# TODO: check uniqueness of symbol names

src/kirin/lowering/python/traits.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def lower(
130130
args, kwargs = self.lower_Call_inputs(stmt, state, node)
131131
return state.current_frame.push(stmt(*args.values(), **kwargs))
132132

133-
def verify(self, node: StatementType):
133+
def verify(self, node: ir.Statement):
134134
assert len(node.regions) == 0, "FromPythonCall statements cannot have regions"
135135
assert (
136136
len(node.successors) == 0
@@ -264,13 +264,13 @@ def lower(
264264
state.current_frame.defs[result.name] = result
265265
return
266266

267-
def verify(self, stmt: ir.Statement):
267+
def verify(self, node: ir.Statement):
268268
assert (
269-
len(stmt.regions) == 1
269+
len(node.regions) == 1
270270
), "FromPythonWithSingleItem statements must have one region"
271271
assert (
272-
len(stmt.successors) == 0
272+
len(node.successors) == 0
273273
), "FromPythonWithSingleItem statements cannot have successors"
274274
assert (
275-
len(stmt.results) <= 1
275+
len(node.results) <= 1
276276
), "FromPythonWithSingleItem statements can have at most one result"

0 commit comments

Comments
 (0)