Skip to content

Update type annotations for passes #2230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions onnxscript/ir/passes/_pass_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import dataclasses
import logging
from typing import Sequence
from typing import Literal, Sequence, final

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

@property
def in_place(self) -> bool:
@final
def in_place(self) -> Literal[True]:
"""An in-place pass is in place."""
return True

@property
def changes_input(self) -> bool:
@final
def changes_input(self) -> Literal[True]:
"""An in-place pass changes the input model."""
return True


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

@property
def in_place(self) -> bool:
@final
def in_place(self) -> Literal[False]:
"""A functional pass is not in place."""
return False

@property
def changes_input(self) -> bool:
@final
def changes_input(self) -> Literal[False]:
"""A functional pass does not change the input model."""
return False


Expand Down
Loading