Skip to content

fix: __all__ references tilecpp even when the backend is unavailable - #184

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/init-all-references-tilecpp-even-when-the
Open

fix: __all__ references tilecpp even when the backend is unavailable#184
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/init-all-references-tilecpp-even-when-the

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in src/tilegym/ops/__init__.py: all references tilecpp even when the backend is unavailable.

Changes

  • src/tilegym/ops/__init__.py: all references tilecpp even when the backend is unavailable.

Details

--- a/src/tilegym/ops/__init__.py
+++ b/src/tilegym/ops/__init__.py
@@ -1,3 +1,5 @@
-# Import CUDA Tile C++ backend if available
-if is_backend_available("tilecpp"):
-    from . import tilecpp
+# Import CUDA Tile C++ backend if available
+if is_backend_available("tilecpp"):
+    from . import tilecpp
+else:
+    tilecpp = None  # type: ignore

Tests

  • tests/test_ops_init.py
--- /dev/null
+++ b/tests/test_ops_init.py
@@ -0,0 +1,21 @@
+"""Regression tests for optional tilecpp export in tilegym.ops."""
+import tilegym.ops as ops
+
+
+def test_tilecpp_name_is_always_bound():
+    """When the tilecpp backend is unavailable, the name must still exist."""
+    assert hasattr(ops, "tilecpp")
+
+
+def test_tilecpp_exported_only_when_available():
+    if ops.tilecpp is None:
+        assert "tilecpp" not in ops.__all__
+    else:
+        assert "tilecpp" in ops.__all__
+
+
+def test_star_import_does_not_raise_when_tilecpp_unavailable():
+    # ``from tilegym.ops import *`` previously raised AttributeError when
+    # tilecpp was unavailable because ``__all__`` still referenced it.
+    namespace = {}
+    exec("from tilegym.ops import *", namespace)
+    assert ("tilecpp" in namespace) == (ops.tilecpp is not None)

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant