Skip to content

Commit 1d7aea3

Browse files
authored
Update type annotations for passes (#2230)
More clear on the documentation site.
1 parent decab2e commit 1d7aea3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

onnxscript/ir/passes/_pass_infra.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import dataclasses
1818
import logging
19-
from typing import Sequence
19+
from typing import Literal, Sequence, final
2020

2121
__all__ = [
2222
"PassBase",
@@ -180,23 +180,31 @@ class InPlacePass(PassBase):
180180
"""A pass that modifies the input model in place and returns it."""
181181

182182
@property
183-
def in_place(self) -> bool:
183+
@final
184+
def in_place(self) -> Literal[True]:
185+
"""An in-place pass is in place."""
184186
return True
185187

186188
@property
187-
def changes_input(self) -> bool:
189+
@final
190+
def changes_input(self) -> Literal[True]:
191+
"""An in-place pass changes the input model."""
188192
return True
189193

190194

191195
class FunctionalPass(PassBase):
192196
"""A pass that returns a new model but does not modify the input model."""
193197

194198
@property
195-
def in_place(self) -> bool:
199+
@final
200+
def in_place(self) -> Literal[False]:
201+
"""A functional pass is not in place."""
196202
return False
197203

198204
@property
199-
def changes_input(self) -> bool:
205+
@final
206+
def changes_input(self) -> Literal[False]:
207+
"""A functional pass does not change the input model."""
200208
return False
201209

202210

0 commit comments

Comments
 (0)