Skip to content

Conversation

@isVoid
Copy link
Collaborator

@isVoid isVoid commented Dec 2, 2025

This is a sub-issue from #247 . Previously we have prefix removal feature for standalone functions. This PR expands the feature to Struct and Enums. Assuming a prefix named _prefix_ is to be removed, a struct named _prefix_Foo is named Foo in python. A enum defined below:

enum _prefix_Fruit {
     _prefix_Apple,
     _prefix_Banana
};

will be exported as:

Fruit(IntEnum):
    Apple = 0
    Banana = 1

in python. This is to say that the prefix removal is applicable to both enum name as well as the members.

Summary by CodeRabbit

  • New Features

    • Configurable prefix removal for enums, structs, and functions so exported Python names omit configured prefixes.
    • Enum symbol list is now exposed in module exports for easier discovery.
  • Refactor

    • Centralized prefix-removal and unified Python-facing name handling across binding generation and symbol registration.
    • Rendering internals now propagate Python-visible names consistently.
  • Tests

    • Added/updated tests to verify prefix removal and symbol exposure; tests invoke kernels directly and reset renderer/function caches.
  • Documentation

    • Clarified enum registration docstring.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

Centralized prefix-removal into a utility and threaded configurable prefix-removal lists from the binding generator into enum, struct, and function renderers; renderers and the symbol tracker now register and emit transformed Python-facing names instead of original C++ identifiers.

Changes

Cohort / File(s) Summary
Utility
numbast/src/numbast/utils.py
Added _apply_prefix_removal(name: str, prefix_to_remove: list[str]) -> str to strip configured prefixes from names.
Renderer core & enum tracking
numbast/src/numbast/static/renderer.py
Added BaseRenderer._enum_symbols: list[str], implemented _get_enum_symbols(), updated get_all_exposed_symbols() and clear_base_renderer_cache() to include _ENUM_SYMBOLS and extend __all__.
Enum rendering
numbast/src/numbast/static/enum.py
StaticEnumRenderer / StaticEnumsRenderer accept enum_prefix_removal; use _apply_prefix_removal to derive _enum_name and per-enumerator Python names; use transformed names for registration and emitted enum code; append transformed names to renderer symbol state.
Function rendering
numbast/src/numbast/static/function.py
Removed per-class prefix-removal helpers; StaticNonOperatorFunctionRenderer uses top-level _apply_prefix_removal to compute Python function names and updates tracked public function symbols accordingly.
Struct rendering
numbast/src/numbast/static/struct.py
Introduced python_struct_name/_python_struct_name and threaded struct_prefix_removal through constructors and renderers; renderers and templates use _python_struct_name for type/class names, registrations, typing and lowering; several __init__ signatures changed and a per-method renderer class adjusted/renamed.
Binding generator integration
numbast/src/numbast/tools/static_binding_generator.py
_generate_enums() and _generate_structs() signatures extended to accept prefix-removal lists; _static_binding_generator() now passes config.api_prefix_removal entries for Enum and Struct into renderers.
Tests — config
numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2
Added explicit Types/Data Models entries and API Prefix Removal rules to strip __internal__ for Struct and Enum and __nv__ for Enum enumerators.
Tests — fixtures & tests
numbast/src/numbast/tools/tests/prefix_removal.cuh, numbast/src/numbast/tools/tests/test_prefix_removal.py, numbast/src/numbast/tools/tests/test_symbol_exposure.py
Added __internal__Foo struct and __internal__Bar enum fixtures; updated tests to assert transformed symbols (e.g., "Foo" present, "__internal__Foo" absent), run kernel in-process, and clear renderer/function registries at test start.
Types docstring
numbast/src/numbast/static/types.py
Added docstring to register_enum_type_str describing its purpose; no signature changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Cfg as Configuration
    participant Gen as BindingGenerator
    participant UT as Utils:_apply_prefix_removal
    participant ER as EnumRenderer
    participant SR as StructRenderer
    participant FR as FunctionRenderer
    participant SYM as BaseRenderer/SymbolTracker

    Cfg->>Gen: provide api_prefix_removal map
    Gen->>ER: instantiate with enum_prefix_removal
    Gen->>SR: instantiate with struct_prefix_removal
    Gen->>FR: instantiate/pass function prefix removal

    ER->>UT: _apply_prefix_removal("__internal__Bar", ["__internal__","__nv__"])
    UT-->>ER: "Bar" and enumerators "BAR_A","BAR_B"
    ER->>SYM: register "Bar" in _enum_symbols / __all__

    SR->>UT: _apply_prefix_removal("__internal__Foo", ["__internal__"])
    UT-->>SR: "Foo"
    SR->>SYM: register "Foo" as public type name / aliases

    FR->>UT: _apply_prefix_removal("prefix_foo", [...])
    UT-->>FR: "foo"
    FR->>SYM: register "foo" in function symbols

    SYM->>SYM: assemble and emit __all__ and _ENUM_SYMBOLS using transformed names
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

  • Pay special attention to numbast/src/numbast/static/struct.py for signature changes, renames, and propagation of _python_struct_name.
  • Verify symbol registration and cache clear in numbast/src/numbast/static/renderer.py and numbast/src/numbast/static/enum.py.
  • Confirm _apply_prefix_removal usage sites (function.py, enum.py, struct.py) and test setup calls (test_symbol_exposure.py) to avoid cross-test contamination.
  • Check binding generator mapping in numbast/src/numbast/tools/static_binding_generator.py for correct config wiring.

Poem

A rabbit nibbles prefixes away,
Hops names clean so bindings play,
"internal" left behind,
Public names hop out aligned,
Rabbit cheers — the symbols stay! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.17% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Allow Prefix Removal for Struct and Enums' accurately describes the main feature addition - extending prefix removal capability to Structs and Enums, which aligns with the PR objectives.
✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cee1bb and 59eb27d.

📒 Files selected for processing (3)
  • numbast/src/numbast/static/enum.py (3 hunks)
  • numbast/src/numbast/static/struct.py (19 hunks)
  • numbast/src/numbast/tools/tests/test_prefix_removal.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
numbast/src/numbast/static/enum.py (2)
numbast/src/numbast/utils.py (1)
  • _apply_prefix_removal (321-338)
numbast/src/numbast/static/types.py (1)
  • register_enum_type_str (19-23)
numbast/src/numbast/tools/tests/test_prefix_removal.py (2)
numbast/src/numbast/tools/tests/test_cli.py (4)
  • kernel (19-35)
  • kernel (25-28)
  • kernel (343-345)
  • kernel (455-456)
numbast/src/numbast/static/tests/data/src/struct.cu (1)
  • get_x (10-10)
numbast/src/numbast/static/struct.py (4)
ast_canopy/ast_canopy/decl.py (4)
  • StructMethod (230-290)
  • param_types (100-101)
  • name (404-405)
  • name (541-542)
numbast/src/numbast/static/renderer.py (1)
  • BaseRenderer (15-122)
numbast/src/numbast/static/types.py (1)
  • to_numba_type_str (33-87)
numbast/src/numbast/static/function.py (2)
  • _render_decl_device (226-254)
  • _render (645-695)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test Wheels / amd64, 3.10, 12.9.1, ubuntu24.04, l4
🔇 Additional comments (16)
numbast/src/numbast/static/enum.py (5)

12-12: LGTM: Import added for prefix removal utility.

The import of _apply_prefix_removal is correct and aligns with the centralized utility approach described in the AI summary.


32-42: LGTM: Enum name prefix removal correctly implemented.

The constructor properly avoids the mutable default argument anti-pattern by using None as the default, and the prefix removal is correctly applied to the enum name before registering it as a symbol.


49-49: LGTM: C-type registration correctly uses original enum name as key.

This correctly addresses the past review feedback. Using self._decl.name (original C name with prefix) as the key and self._enum_name (Python-facing name without prefix) as the value ensures that C++ types like prefix_Fruit correctly map to the generated Python enum Fruit.


52-60: LGTM: Enum member prefix removal correctly implemented.

The prefix removal is correctly applied to each enumerator before rendering, which aligns with the PR objective of removing prefixes from both enum type names and their members. This addresses the past review feedback requesting this feature.


73-87: LGTM: Collection renderer correctly propagates prefix removal.

The StaticEnumsRenderer correctly:

  1. Avoids mutable default arguments by using None
  2. Has the corrected list[str] type annotation for _python_rendered (previously incorrectly typed as list[tuple[set[str], str]])
  3. Propagates the prefix removal configuration to individual enum renderers

All past review feedback has been properly addressed.

numbast/src/numbast/static/struct.py (8)

27-27: LGTM: Import added for prefix removal utility.

The import is correctly added and consistent with the centralized utility pattern used across enum and struct renderers.


143-153: LGTM: Dual-name pattern correctly established.

The constructor properly accepts and stores both the original C++ struct name (_struct_name) for C interop and the Python-facing name (_python_struct_name) for type registration and lowering decorators. This dual-name approach is essential for correct prefix removal.


253-253: LGTM: Python-facing name correctly used in lowering decorator.

The @lower decorator correctly uses _python_struct_name to register the constructor implementation against the Python-visible struct name, ensuring that user code referencing the transformed name (e.g., Foo instead of __internal__Foo) will find the correct lowering.


338-392: LGTM: Constructor renderer correctly propagates Python-facing name.

The StaticStructCtorsRenderer properly:

  1. Accepts and stores python_struct_name
  2. Uses it in typing templates for Python API registration (line 379)
  3. Propagates it to individual constructor renderers (line 392)

This ensures constructors are registered under the transformed name.


672-866: LGTM: Method renderer refactored to single-method pattern with correct naming.

The refactoring from a multi-method renderer to StaticStructRegularMethodRenderer (single method) follows the same pattern as the constructor renderer:

  1. Accepts both C++ and Python-facing struct names
  2. Uses _python_struct_name correctly in the @lower decorator (line 838)
  3. Exposes a signature_str property for typing template generation

This architectural consistency improves maintainability.


869-944: LGTM: Methods collection renderer properly orchestrates singular renderers.

The StaticStructRegularMethodsRenderer correctly:

  1. Accepts and propagates python_struct_name to individual method renderers (line 911)
  2. Collects signature strings from each renderer (line 926)
  3. Generates typing templates per method name with aggregated signatures

The pattern is consistent with constructor rendering.


1044-1098: LGTM: Struct renderer correctly applies prefix removal and maintains C-type mapping.

The top-level struct renderer correctly:

  1. Applies _apply_prefix_removal to compute _python_struct_name (lines 1056-1058)
  2. Uses the original C++ name as the key in CTYPE_TO_NBTYPE_STR (line 1093), ensuring C++ declarations with prefixes map correctly to Numba types
  3. Exposes the Python-facing name in _record_symbols (line 1098), so users see Foo instead of __internal__Foo
  4. Uses _python_struct_name consistently for all Python-facing identifiers (lines 1084-1089, 1116, 1131)

This pattern mirrors the enum renderer and correctly bridges C++ to Python naming.


1377-1420: LGTM: Collection renderer correctly propagates prefix removal configuration.

The StaticStructsRenderer properly accepts the struct_prefix_removal configuration and passes it to each StaticStructRenderer instance (line 1419), completing the propagation chain from the binding generator to individual struct rendering.

numbast/src/numbast/tools/tests/test_prefix_removal.py (3)

4-4: LGTM: Import enables in-process kernel testing.

The cuda import from numba enables direct CUDA JIT compilation and execution, which is more efficient than the previous subprocess-based testing approach.


25-37: LGTM: Assertions correctly validate struct and enum prefix removal.

The test assertions properly verify that:

  1. Prefix-stripped struct name Foo is exposed (not __internal__Foo)
  2. Prefix-stripped enum name Bar is exposed (not __internal__Bar)

This validates the core PR objective of removing prefixes from both structs and enums.


39-53: LGTM: Functional test validates prefix-removed symbols in CUDA kernel.

The test comprehensively validates that prefix-removed symbols are correctly bound and functional by:

  1. Invoking function foo (line 45)
  2. Constructing struct Foo, calling its method get_x(), and accessing field x (lines 46-48)
  3. Accessing enum Bar members BAR_A and BAR_B (lines 50-51)
  4. Successfully executing the kernel (line 53)

This validates the end-to-end functionality of prefix removal for functions, structs, and enums.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@isVoid isVoid marked this pull request as ready for review December 2, 2025 19:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
numbast/src/numbast/tools/tests/test_prefix_removal.py (1)

4-49: Add explicit __all__ assertions for enums.

The test nicely checks function and struct prefix removal and exercises the enum in a kernel, but it never asserts that:

  • Bar is present in __all__, and
  • __internal__Bar is absent.

Adding these would fully cover the enum side of the feature:

     # Verify that the function is exposed as "foo" (without the "prefix_" prefix)
     assert "foo" in alls, f"Expected 'foo' in __all__, got: {alls}"
     assert "Foo" in alls, f"Expected 'Foo' in __all__, got: {alls}"
 
     # Verify that the original name "prefix_foo" is NOT exposed
     assert "prefix_foo" not in alls, (
         f"Expected 'prefix_foo' NOT in __all__, got: {alls}"
     )
     assert "__internal__Foo" not in alls, (
         f"Expected '__internal__Foo' NOT in __all__, got: {alls}"
     )
+    assert "Bar" in alls, f"Expected 'Bar' in __all__, got: {alls}"
+    assert "__internal__Bar" not in alls, (
+        f"Expected '__internal__Bar' NOT in __all__, got: {alls}"
+    )
numbast/src/numbast/static/struct.py (2)

1044-1057: Avoid mutable default argument.

Line 1050 uses a mutable default struct_prefix_removal: list[str] = []. In Python, default mutable arguments are shared across all calls, which can lead to unexpected behavior if the list is ever modified.

Apply this diff:

     def __init__(
         self,
         decl: Struct,
         parent_type: type | None,
         data_model: type | None,
         header_path: os.PathLike | str,
-        struct_prefix_removal: list[str] = [],
+        struct_prefix_removal: list[str] | None = None,
         aliases: list[str] = [],
     ):
         super().__init__(decl)
         self._python_struct_name = _apply_prefix_removal(
-            decl.name, struct_prefix_removal
+            decl.name, struct_prefix_removal or []
         )

Note: The same issue exists for aliases parameter.


1375-1418: Avoid mutable default argument.

Line 1380 uses a mutable default struct_prefix_removal: list[str] = []. Same issue as in StaticStructRenderer.

Apply this diff:

     def __init__(
         self,
         decls: list[Struct],
         specs: dict[str, tuple[type | None, type | None, os.PathLike]],
         default_header: os.PathLike | str | None = None,
-        struct_prefix_removal: list[str] = [],
+        struct_prefix_removal: list[str] | None = None,
         excludes: list[str] = [],
     ):
         self._decls = decls
         self._specs = specs
         self._default_header = default_header
-        self._struct_prefix_removal = struct_prefix_removal
+        self._struct_prefix_removal = struct_prefix_removal or []

Note: The same issue exists for excludes parameter.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae49180 and 38099e1.

📒 Files selected for processing (9)
  • numbast/src/numbast/static/enum.py (4 hunks)
  • numbast/src/numbast/static/function.py (2 hunks)
  • numbast/src/numbast/static/renderer.py (3 hunks)
  • numbast/src/numbast/static/struct.py (19 hunks)
  • numbast/src/numbast/tools/static_binding_generator.py (4 hunks)
  • numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2 (1 hunks)
  • numbast/src/numbast/tools/tests/prefix_removal.cuh (1 hunks)
  • numbast/src/numbast/tools/tests/test_prefix_removal.py (2 hunks)
  • numbast/src/numbast/utils.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
numbast/src/numbast/tools/static_binding_generator.py (1)
numbast/src/numbast/static/enum.py (1)
  • StaticEnumsRenderer (63-105)
numbast/src/numbast/static/enum.py (2)
numbast/src/numbast/utils.py (1)
  • _apply_prefix_removal (321-338)
numbast/src/numbast/static/types.py (1)
  • register_enum_type_str (19-22)
numbast/src/numbast/tools/tests/test_prefix_removal.py (3)
numbast/src/numbast/tools/tests/test_macros.py (2)
  • kernel (16-32)
  • kernel (23-26)
numbast/src/numbast/tools/tests/test_cli.py (4)
  • kernel (19-35)
  • kernel (25-28)
  • kernel (343-345)
  • kernel (455-456)
numbast/src/numbast/static/tests/data/src/struct.cu (1)
  • get_x (10-10)
numbast/src/numbast/static/function.py (1)
numbast/src/numbast/utils.py (2)
  • make_function_shim (125-177)
  • _apply_prefix_removal (321-338)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Conda Python / test (amd64, 3.10, 12.8.0, rockylinux8, l4, earliest)
  • GitHub Check: Test Wheels / amd64, 3.13, 13.0.1, ubuntu24.04, l4
🔇 Additional comments (13)
numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2 (1)

12-22: Config wiring for struct/enum prefix removal looks consistent.

The added Types, Data Models, and API Prefix Removal.Struct/Enum entries line up with the new prefix-removal flow and should give the generator what it needs for __internal__Foo and __internal__Bar.

numbast/src/numbast/tools/tests/prefix_removal.cuh (1)

8-17: Struct and enum fixtures for prefix removal look sound.

__internal__Foo and __internal__Bar are minimal but sufficient to exercise struct construction, method access, and enum usage under prefix removal.

numbast/src/numbast/static/function.py (1)

19-20: Function prefix removal via shared helper and symbol override looks correct.

Using _apply_prefix_removal to compute _python_func_name and then swapping the _function_symbols entry to the Python-facing name keeps __all__ aligned with the exposed API while leaving operator handling unchanged. The guarded remove avoids issues when the base name isn’t present.

Also applies to: 416-426, 433-439

numbast/src/numbast/static/struct.py (10)

22-28: LGTM!

The import of _apply_prefix_removal is correctly added and will be used in StaticStructRenderer.__init__ to derive the Python-facing struct name.


143-157: LGTM!

The python_struct_name parameter is properly added and stored for use in the lowering template.


249-259: LGTM!

Correctly using _python_struct_name in the lowering template so the @lower decorator registers against the Python-facing struct name.


338-397: LGTM!

The python_struct_name parameter is correctly threaded through StaticStructCtorsRenderer and passed to child renderers. The typing template properly uses the Python-facing name for globals() lookup.


729-791: LGTM!

The StaticStructRegularMethodRenderer correctly accepts and uses python_struct_name. The signature_str property properly references _struct_type_name for the receiver type, and the lowering template at line 838 correctly uses the Python-facing struct name.


879-915: LGTM!

The python_struct_name parameter is correctly propagated to child StaticStructRegularMethodRenderer instances.


1080-1096: LGTM!

Internal naming correctly uses _python_struct_name for Python-facing identifiers. The CTYPE_TO_NBTYPE_STR mapping appropriately uses the raw C++ struct name as key (for C type resolution) while mapping to the Python-derived type name.


1110-1130: LGTM!

The _python_struct_name is correctly used in both the typing and Python API templates, ensuring users see the prefix-removed name.


1226-1259: LGTM!

The _python_struct_name is correctly propagated to both the regular methods renderer and constructors renderer.


1261-1277: Verify: Conversion operators don't need prefix removal.

The StaticStructConversionOperatorRenderer and StaticStructConversionOperatorsRenderer classes were not updated with python_struct_name. This appears intentional since @lower_cast uses type objects rather than string names, so the prefix-removed naming flows through the type system automatically.

Please confirm this is the intended behavior—that conversion operators inherit the correct naming via _struct_type_name without needing explicit python_struct_name propagation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38099e1 and 6bd4b73.

📒 Files selected for processing (1)
  • numbast/src/numbast/tools/tests/test_symbol_exposure.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
numbast/src/numbast/tools/tests/test_symbol_exposure.py (2)
numbast/src/numbast/static/renderer.py (1)
  • clear_base_renderer_cache (125-133)
numbast/src/numbast/static/function.py (1)
  • clear_function_apis_registry (712-719)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build Conda Python / build (arm64, 3.10, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.10, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.11, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.11, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.13, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.12, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.12, 12.9.1, rockylinux8)
🔇 Additional comments (1)
numbast/src/numbast/tools/tests/test_symbol_exposure.py (1)

8-9: New cache/reset imports look correct and localized

The imports for clear_base_renderer_cache and clear_function_apis_registry match their definitions and keep the test’s dependencies explicit. No issues here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
numbast/src/numbast/static/enum.py (1)

71-76: Fix mutable default argument and incorrect type annotation.

Two issues:

  1. Using a mutable default argument (enum_prefix_removal: list[str] = []) is a Python anti-pattern.
  2. The type annotation list[tuple[set[str], str]] is incorrect; the code appends strings (line 85) and joins them (line 90), so it should be list[str].

Apply this diff:

-    def __init__(self, decls: list[Enum], enum_prefix_removal: list[str] = []):
+    def __init__(self, decls: list[Enum], enum_prefix_removal: list[str] | None = None):
         super().__init__(decls)
         self._decls = decls
-        self._enum_prefix_removal = enum_prefix_removal
+        self._enum_prefix_removal = enum_prefix_removal or []
 
-        self._python_rendered: list[tuple[set[str], str]] = []
+        self._python_rendered: list[str] = []
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd4b73 and 572f9a9.

📒 Files selected for processing (5)
  • numbast/src/numbast/static/enum.py (3 hunks)
  • numbast/src/numbast/static/renderer.py (4 hunks)
  • numbast/src/numbast/static/types.py (1 hunks)
  • numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2 (1 hunks)
  • numbast/src/numbast/tools/tests/prefix_removal.cuh (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
numbast/src/numbast/static/enum.py (2)
numbast/src/numbast/utils.py (1)
  • _apply_prefix_removal (321-338)
numbast/src/numbast/static/types.py (1)
  • register_enum_type_str (19-23)
🔇 Additional comments (9)
numbast/src/numbast/static/types.py (1)

20-20: LGTM! Clear documentation added.

The docstring accurately describes the function's purpose in the enum type registration flow.

numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2 (1)

12-23: LGTM! Test configuration properly structured.

The configuration correctly declares the test types and prefix removal rules for structs and enums, supporting the new prefix removal feature.

numbast/src/numbast/tools/tests/prefix_removal.cuh (1)

8-17: LGTM! Test coverage for prefix removal is comprehensive.

The test code properly exercises multiple prefix scenarios: __internal__ for the struct and enum name, and __nv__ for enum members.

numbast/src/numbast/static/enum.py (2)

47-47: LGTM! C-type registration correctly uses original and transformed names.

The call to register_enum_type_str properly uses the original C++ enum name (self._decl.name) as the key and the transformed Python name (self._enum_name) as the value, maintaining the correct mapping for C++ types with prefixes.


50-58: LGTM! Enum member prefix removal implemented correctly.

The code properly applies prefix removal to each enum member before rendering, ensuring both the enum name and its members have prefixes stripped as specified in the PR objectives.

numbast/src/numbast/static/renderer.py (4)

86-88: LGTM! Enum symbol tracking follows established patterns.

The _enum_symbols list follows the same design as the existing _nbtype_symbols, _record_symbols, and _function_symbols lists.


134-134: LGTM! Cache clearing properly includes enum symbols.

The _enum_symbols.clear() call ensures enum state is reset consistently with other symbol caches, addressing the past review concern.


252-261: LGTM! Enum symbol getter mirrors existing patterns.

The _get_enum_symbols() function follows the same structure as _get_nbtype_symbols(), _get_record_symbols(), and _get_function_symbols().


276-283: LGTM! Enum symbols properly integrated into all exposure.

Enum symbols are correctly added to the __all__ export list alongside other symbol types.

@isVoid
Copy link
Collaborator Author

isVoid commented Dec 2, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
numbast/src/numbast/utils.py (1)

321-338: Document the prefix_to_remove parameter.

The docstring is missing documentation for the prefix_to_remove parameter in the Parameters section. Based on learnings, this was requested in a previous review but appears incomplete.

Apply this diff:

     Parameters
     ----------
     name : str
         The original struct, function or enum type name, or named enum values.
+    prefix_to_remove : list[str]
+        List of prefixes to attempt removal from the name.
 
     Returns
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e719a3 and 3cee1bb.

📒 Files selected for processing (3)
  • numbast/src/numbast/static/enum.py (3 hunks)
  • numbast/src/numbast/tools/static_binding_generator.py (5 hunks)
  • numbast/src/numbast/utils.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
numbast/src/numbast/tools/static_binding_generator.py (2)
numbast/src/numbast/static/struct.py (1)
  • StaticStructsRenderer (1346-1454)
numbast/src/numbast/static/enum.py (1)
  • StaticEnumsRenderer (67-109)
numbast/src/numbast/static/enum.py (2)
numbast/src/numbast/utils.py (1)
  • _apply_prefix_removal (321-338)
numbast/src/numbast/static/types.py (1)
  • register_enum_type_str (19-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test Wheels / amd64, 3.10, 12.9.1, ubuntu24.04, l4
  • GitHub Check: Test Wheels / arm64, 3.11, 12.9.1, ubuntu24.04, a100
  • GitHub Check: Test Wheels / amd64, 3.13, 13.0.1, ubuntu24.04, l4
  • GitHub Check: Test Wheels / arm64, 3.12, 13.0.1, ubuntu24.04, a100
  • GitHub Check: Build Conda Python / build (arm64, 3.12, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.11, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.12, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.10, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (arm64, 3.13, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.11, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.13, 12.9.1, rockylinux8)
  • GitHub Check: Build Conda Python / build (amd64, 3.10, 12.9.1, rockylinux8)
🔇 Additional comments (8)
numbast/src/numbast/tools/static_binding_generator.py (4)

91-92: LGTM! Docstring improvement enhances discoverability.

The update clearly lists the acceptable keywords for api_prefix_removal, making it easy for users to discover and use struct/enum prefix-removal features.


378-385: LGTM! Struct prefix-removal parameter correctly threaded.

The struct_prefix_removal parameter is properly added to the function signature and passed through to StaticStructsRenderer.


426-431: LGTM! Enum prefix-removal parameter correctly threaded.

The enum_prefix_removal parameter is properly added to the function signature and passed through to StaticEnumsRenderer.


530-532: LGTM! Configuration properly propagated to renderers.

The prefix-removal configuration is correctly extracted from config.api_prefix_removal using safe .get() access and passed to the appropriate rendering functions.

Also applies to: 538-538

numbast/src/numbast/static/enum.py (4)

32-42: LGTM! Mutable default argument correctly fixed.

The constructor properly uses None as the default and falls back to an empty list, avoiding the mutable default argument anti-pattern. The prefix-removal logic is correctly applied to compute the Python-facing enum name.


49-49: LGTM! Enum type registration correctly maps C++ name to Python name.

The registration correctly uses the original C++ name (self._decl.name) as the key and the prefix-stripped name (self._enum_name) as the value, ensuring C++ types with prefixes map correctly to the generated Python enums.


55-60: LGTM! Prefix removal correctly applied to enum members.

Each enumerator now has prefix removal applied via _apply_prefix_removal, ensuring both the enum type name and its members are consistently transformed for Python, as specified in the PR objectives.


78-78: LGTM! Type annotation correctly fixed.

The _python_rendered type annotation is now correctly specified as list[str], matching its actual usage where string blocks are appended and later joined.

@isVoid
Copy link
Collaborator Author

isVoid commented Dec 2, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Note

Docstrings generation - SKIPPED
Skipped regeneration as there are no new commits. Docstrings already generated for this pull request at #261.

coderabbitai bot added a commit that referenced this pull request Dec 2, 2025
Docstrings generation was requested by @isVoid.

* #259 (comment)

The following files were modified:

* `numbast/src/numbast/static/enum.py`
* `numbast/src/numbast/static/function.py`
* `numbast/src/numbast/static/renderer.py`
* `numbast/src/numbast/static/struct.py`
* `numbast/src/numbast/static/types.py`
* `numbast/src/numbast/tools/static_binding_generator.py`
* `numbast/src/numbast/tools/tests/test_prefix_removal.py`
* `numbast/src/numbast/utils.py`
@isVoid isVoid merged commit c41116b into NVIDIA:main Dec 2, 2025
26 checks passed
@isVoid isVoid deleted the fea-enum-prefix-removal branch December 2, 2025 21:40
isVoid added a commit that referenced this pull request Dec 3, 2025
Docstrings generation was requested by @isVoid.

* #259 (comment)

The following files were modified:

* `numbast/src/numbast/static/enum.py`
* `numbast/src/numbast/static/function.py`
* `numbast/src/numbast/static/renderer.py`
* `numbast/src/numbast/static/struct.py`
* `numbast/src/numbast/static/types.py`
* `numbast/src/numbast/tools/static_binding_generator.py`
* `numbast/src/numbast/tools/tests/test_prefix_removal.py`
* `numbast/src/numbast/utils.py`

<details>
<summary>These files were kept as they were</summary>

* `numbast/src/numbast/tools/tests/test_symbol_exposure.py`

</details>

<details>
<summary>These file types are not supported</summary>

* `numbast/src/numbast/tools/tests/config/prefix_removal.yml.j2`
* `numbast/src/numbast/tools/tests/prefix_removal.cuh`

</details>

<details>
<summary>ℹ️ Note</summary><blockquote>

CodeRabbit cannot perform edits on its own pull requests yet.

</blockquote></details>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
@isVoid isVoid mentioned this pull request Dec 11, 2025
isVoid added a commit that referenced this pull request Dec 11, 2025
Numbast 0.6.0 updates numba-cuda pinnings to 0.21.0+

- bump 0.6.0
- Eagerly use all vended `numba.cuda` modules, Bump supported Numba-CUDA
version to 0.21+ (#239)
- Support Functions Typed with `__nv_bfloat16_raw` (#262)
- Use `TargetRegistry.lower_cast` in separate registry mode (#263)
- 📝 Add docstrings to `fea-enum-prefix-removal` (#261)
- Allow Prefix Removal for Struct and Enums (#259)
- Enable CodeRabbit Auto Review (#257)
- use readme.md as PYPI description readme (#254)

Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
isVoid added a commit that referenced this pull request Jan 21, 2026
Manual `clear_base_renderer_cache()` and
`clear_function_apis_registry()` calls scattered across test files to
prevent cross-test pollution. Consolidates these into a single `autouse`
fixture.

## Changes

- **`conftest.py`**: Added `reset_state()` fixture with `autouse=True`
that executes both clear functions before each test
- **`test_symbol_exposure.py`**: Removed manual clear calls (now handled
by fixture)
- **`test_cli.py`**: Removed manual clear calls from 10 test functions

## Impact

All 15 test files in `numbast/src/numbast/tools/tests/` now
automatically reset state before each test. Single point of maintenance
for state reset logic.

```python
@pytest.fixture(autouse=True)
def reset_state():
    """Reset global state before each test to avoid cross-test pollution."""
    clear_base_renderer_cache()
    clear_function_apis_registry()
    yield
```

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Refactor state reset calls into a shared pytest
fixture</issue_title>
> <issue_description>## Description
> 
> In `numbast/src/numbast/tools/tests/test_symbol_exposure.py`, the test
manually calls `clear_base_renderer_cache()` and
`clear_function_apis_registry()` at the start to avoid cross-test
pollution.
> 
> ## Proposed Change
> 
> Refactor these calls into a shared pytest fixture (optionally with
`autouse=True`) that can be:
> - Placed in the test module or a `conftest.py`
> - Automatically run before each test to guarantee state reset
> - Centralized for reuse across multiple tests if needed
> 
> ## Context
> 
> - PR: #259
> - Discussion:
#259 (comment)
> - Requested by: @isVoid
> 
> ## Implementation Notes
> 
> The fixture should:
> 1. Import and execute `clear_base_renderer_cache()` from
`numbast.static.renderer`
> 2. Import and execute `clear_function_apis_registry()` from
`numbast.static.function`
> 3. Yield control to allow for future teardown/cleanup logic if needed
> 4. Consider using `autouse=True` to automatically apply to all tests
in scope</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #260

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: isVoid <13521008+isVoid@users.noreply.github.com>
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