Skip to content

Commit d274308

Browse files
authored
feat: add get_casted to force linter accepting a type (#360)
while in most cases `.get` is sufficient, having `.get_casted` allows linter to provide more specific auto-complete if the author is pretty sure about the resulting type.
1 parent f75cebc commit d274308

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/kirin/interp/frame.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ def get(self, key: SSAValue) -> ValueType:
125125

126126
ExpectedType = TypeVar("ExpectedType")
127127

128+
def get_casted(self, key: SSAValue, type_: type[ExpectedType]) -> ExpectedType:
129+
"""Same as [`get`][kirin.interp.frame.Frame.get] except it
130+
forces the linter to think the value is of the expected type.
131+
132+
Args:
133+
key(SSAValue): The key to get the value for.
134+
type_(type): The expected type.
135+
136+
Returns:
137+
ExpectedType: The value.
138+
"""
139+
return self.get(key) # type: ignore
140+
128141
def get_typed(self, key: SSAValue, type_: type[ExpectedType]) -> ExpectedType:
129142
"""Similar to [`get`][kirin.interp.frame.Frame.get] but also checks the type.
130143

0 commit comments

Comments
 (0)