Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/openpi/shared/array_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def typecheck(t: T) -> T:
def disable_typechecking():
initial = config.jaxtyping_disable
config.update("jaxtyping_disable", True) # noqa: FBT003
yield
config.update("jaxtyping_disable", initial)
try:
yield
finally:
config.update("jaxtyping_disable", initial)


def check_pytree_equality(*, expected: PyTree, got: PyTree, check_shapes: bool = False, check_dtypes: bool = False):
Expand Down
13 changes: 13 additions & 0 deletions src/openpi/shared/array_typing_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from jaxtyping import config
import pytest

from openpi.shared import array_typing as at


def test_disable_typechecking_restores_flag_on_exception():
initial = config.jaxtyping_disable

with pytest.raises(RuntimeError, match="boom"), at.disable_typechecking():
raise RuntimeError("boom")

assert config.jaxtyping_disable == initial