[MLIR] [Python] Fixed type errors in get_parent_of_type (#186079)
`op.parent` can be `None`, and `None` is not assignable to a variable with type `OpView | Operation`. Both mypy and Pyrefly flag this.
This commit is contained in:
parent
2ff88c662d
commit
d135d33497
1 changed files with 5 additions and 5 deletions
|
|
@ -35,13 +35,13 @@ def get_parent_of_type(op: OpView | Operation, op_class: type[OpView]) -> OpView
|
|||
if not (isinstance(op_class, type) and issubclass(op_class, OpView)):
|
||||
raise TypeError(f"op_class must be an OpView subclass, got {op_class!r}")
|
||||
try:
|
||||
op = op.parent
|
||||
parent = op.parent
|
||||
except ValueError:
|
||||
return None # No parent chain.
|
||||
while op is not None:
|
||||
if isinstance(op.opview, op_class):
|
||||
return op.opview
|
||||
op = op.parent
|
||||
while parent is not None:
|
||||
if isinstance(parent.opview, op_class):
|
||||
return parent.opview
|
||||
parent = parent.parent
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue