From 6f4a94e5b4457b2f2a5ecd9f2360935d86e62c40 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 15 May 2024 15:42:11 -0400 Subject: [PATCH 1/3] Respect the RERUN_STRICT environment variable if not specified in rr.init --- rerun_py/rerun_sdk/rerun/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index ad3d344bb9af..e86a910d532e 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -166,7 +166,7 @@ def init( spawn: bool = False, init_logging: bool = True, default_enabled: bool = True, - strict: bool = False, + strict: bool | None = None, default_blueprint: BlueprintLike | None = None, ) -> None: """ @@ -234,7 +234,8 @@ def init( Should we initialize the logging for this application? strict If `True`, an exceptions is raised on use error (wrong parameter types, etc.). - If `False`, errors are logged as warnings instead. + If `False`, errors are logged as warnings instead. This is the default. + If unset, this can also be overridden using the RERUN_STRICT environment variables. default_blueprint Optionally set a default blueprint to use for this application. If the application already has an active blueprint, the new blueprint won't become active until the user @@ -248,7 +249,8 @@ def init( random.seed(0) np.random.seed(0) - set_strict_mode(strict) + if strict is not None: + set_strict_mode(strict) # Always check whether we are a forked child when calling init. This should have happened # via `_register_on_fork` but it's worth being conservative. From 706007d97b15b0539b953419199ae14914c56274 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 15 May 2024 15:51:32 -0400 Subject: [PATCH 2/3] Tweak docstring --- rerun_py/rerun_sdk/rerun/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index e86a910d532e..cc0b2c147b52 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -233,9 +233,10 @@ def init( init_logging Should we initialize the logging for this application? strict - If `True`, an exceptions is raised on use error (wrong parameter types, etc.). - If `False`, errors are logged as warnings instead. This is the default. - If unset, this can also be overridden using the RERUN_STRICT environment variables. + If `True`, an exception is raised on use error (wrong parameter types, etc.). + If `False`, errors are logged as warnings instead. + If unset, this can alternatively be overridden using the RERUN_STRICT environment variable. + If not otherwise specified, the default behavior will be equivalent to `False`. default_blueprint Optionally set a default blueprint to use for this application. If the application already has an active blueprint, the new blueprint won't become active until the user From 2b440da5d31096965adf32ae27d92802ff4dbd73 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 15 May 2024 18:32:48 -0400 Subject: [PATCH 3/3] Fix strict mode unit tests --- rerun_py/tests/unit/test_exceptions.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rerun_py/tests/unit/test_exceptions.py b/rerun_py/tests/unit/test_exceptions.py index 737c5c688b29..3ffd72d896c8 100644 --- a/rerun_py/tests/unit/test_exceptions.py +++ b/rerun_py/tests/unit/test_exceptions.py @@ -56,7 +56,7 @@ def expected_warnings(warnings: Any, mem: Any, starting_msgs: int, count: int, e def test_stack_tracking() -> None: # Force flushing so we can count the messages os.environ["RERUN_FLUSH_NUM_ROWS"] = "0" - rr.init("rerun_example_strict_mode", spawn=False) + rr.init("rerun_example_strict_mode", strict=False, spawn=False) mem = rr.memory_recording() with pytest.warns(RerunWarning) as warnings: @@ -117,17 +117,24 @@ def test_stack_tracking() -> None: def test_strict_mode() -> None: - # We can disable strict on just this function + rr.set_strict_mode(False) + + # Confirm strict mode is off + with pytest.warns(RerunWarning): + assert outer() == 42 + + # We can enable strict on just this function with pytest.raises(ValueError): outer(strict=True) with pytest.raises(ValueError): uses_context(strict=True) - # We can disable strict mode globally + # We can enable strict mode globally rr.set_strict_mode(True) with pytest.raises(ValueError): outer() + # Clear the global strict mode again rr.set_strict_mode(False)