Fix stub generation issues and enable full Pyright validation in CI/CD#1171
Fix stub generation issues and enable full Pyright validation in CI/CD#1171shi-eric merged 5 commits intoNVIDIA:mainfrom
Conversation
Behavior is similar to range and iter_next, both of which are already hidden Signed-off-by: Eric Shi <ershi@nvidia.com>
Previously multi-line docstrings rendered with inconsistent margins because only the first line was indented within the function directive. Signed-off-by: Eric Shi <ershi@nvidia.com>
📝 WalkthroughWalkthroughRefactors the scalar/type system, moves Quaternion/Transformation typings to Float, merges identical builtin overloads into single stubs, exposes a new Changes
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @warp/_src/context.py:
- Around line 8657-8673: get_return_type_str currently skips explicit None and
unguardedly calls f.value_func(None, None); change it to first set return_type =
f.value_type, then if f.value_func is present attempt to call it inside a
try/except (catch TypeError/Exception) and only overwrite return_type if the
call succeeds, falling back to f.value_type on error; finally, return the
literal "None" when return_type is None, otherwise return type_str(return_type).
Update references in add_builtin_function_stub usage of get_return_type_str so
stubs will emit "-> None" and stub generation won't crash from unsafe
f.value_func calls.
🧹 Nitpick comments (2)
warp/_src/context.py (1)
8921-8941: Prefer comparingFunction.signatureoverinput_typesfor “identical overload” detection.
Usingtuple(sorted(f.input_types.items()))ignores default values/kw-only/varargs semantics that are already captured byFunction.signature. This risks merging overloads that look “same” by dict contents but differ in callable signature.Proposed refactor
- first = non_hidden_overloads[0] - first_inputs = tuple(sorted(first.input_types.items())) - all_same_inputs = all( - tuple(sorted(f.input_types.items())) == first_inputs for f in non_hidden_overloads - ) + first = non_hidden_overloads[0] + all_same_inputs = all(f.signature == first.signature for f in non_hidden_overloads)warp/_src/builtins.py (1)
28-28: Ruff F405 noise fromfrom warp._src.types import *is now hitting many changed lines.If Ruff is enforced in CI for this repo, consider either adding a targeted
# noqa: F403,F405on the star import line, or switching to explicit imports (bigger change). Otherwise, these warnings will keep growing as more typed overloads are added.Also applies to: 427-429, 475-478, 524-527, 742-744, 8828-8840, 9063-9076, 9101-9116, 9134-9142, 9176-9185, 9788-9792, 9803-9807, 9830-9841, 10034-10051, 10161-10179, 10236-10294, 11763-11766
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
.github/workflows/ci.yml.gitlab-ci.ymldocs/_templates/builtins.rstdocs/language_reference/builtins.rstwarp/__init__.pyiwarp/_src/builtins.pywarp/_src/context.pywarp/_src/types.py
💤 Files with no reviewable changes (2)
- .gitlab-ci.yml
- .github/workflows/ci.yml
🧰 Additional context used
🧬 Code graph analysis (3)
warp/__init__.pyi (5)
warp/_src/types.py (2)
Quaternion(264-265)Transformation(268-269)warp/native/tile.h (1)
len(1757-1760)warp/native/array.h (1)
len(2218-2218)warp/native/mat.h (1)
len(5516-5519)warp/native/vec.h (1)
len(2264-2264)
warp/_src/context.py (2)
warp/_src/utils.py (1)
warn(70-84)warp/__init__.pyi (6)
add(5689-5691)add(5694-5696)add(5699-5701)add(5704-5706)add(5709-5711)add(5714-5716)
warp/_src/types.py (2)
exts/omni.warp/omni/warp/nodes/_impl/kernel.py (1)
is_array(254-255)warp/__init__.pyi (6)
add(5689-5691)add(5694-5696)add(5699-5701)add(5704-5706)add(5709-5711)add(5714-5716)
🪛 Ruff (0.14.10)
warp/_src/builtins.py
428-428: quaternion may be undefined, or defined from star imports
(F405)
428-428: Float may be undefined, or defined from star imports
(F405)
477-477: quaternion may be undefined, or defined from star imports
(F405)
477-477: Float may be undefined, or defined from star imports
(F405)
526-526: quaternion may be undefined, or defined from star imports
(F405)
526-526: Float may be undefined, or defined from star imports
(F405)
743-743: quaternion may be undefined, or defined from star imports
(F405)
743-743: Float may be undefined, or defined from star imports
(F405)
8829-8829: quaternion may be undefined, or defined from star imports
(F405)
8829-8829: Float may be undefined, or defined from star imports
(F405)
8838-8838: transformation may be undefined, or defined from star imports
(F405)
8838-8838: Float may be undefined, or defined from star imports
(F405)
9065-9065: quaternion may be undefined, or defined from star imports
(F405)
9065-9065: Float may be undefined, or defined from star imports
(F405)
9075-9075: transformation may be undefined, or defined from star imports
(F405)
9075-9075: Float may be undefined, or defined from star imports
(F405)
9103-9103: quaternion may be undefined, or defined from star imports
(F405)
9103-9103: Float may be undefined, or defined from star imports
(F405)
9114-9114: transformation may be undefined, or defined from star imports
(F405)
9114-9114: Float may be undefined, or defined from star imports
(F405)
9136-9136: quaternion may be undefined, or defined from star imports
(F405)
9136-9136: Float may be undefined, or defined from star imports
(F405)
9179-9179: quaternion may be undefined, or defined from star imports
(F405)
9179-9179: Float may be undefined, or defined from star imports
(F405)
9790-9790: quaternion may be undefined, or defined from star imports
(F405)
9790-9790: Float may be undefined, or defined from star imports
(F405)
9790-9790: quaternion may be undefined, or defined from star imports
(F405)
9790-9790: Float may be undefined, or defined from star imports
(F405)
9791-9791: quaternion may be undefined, or defined from star imports
(F405)
9791-9791: Float may be undefined, or defined from star imports
(F405)
9805-9805: transformation may be undefined, or defined from star imports
(F405)
9805-9805: Float may be undefined, or defined from star imports
(F405)
9805-9805: transformation may be undefined, or defined from star imports
(F405)
9805-9805: Float may be undefined, or defined from star imports
(F405)
9806-9806: transformation may be undefined, or defined from star imports
(F405)
9806-9806: Float may be undefined, or defined from star imports
(F405)
9832-9832: quaternion may be undefined, or defined from star imports
(F405)
9832-9832: Float may be undefined, or defined from star imports
(F405)
9832-9832: quaternion may be undefined, or defined from star imports
(F405)
9832-9832: Float may be undefined, or defined from star imports
(F405)
9833-9833: quaternion may be undefined, or defined from star imports
(F405)
9833-9833: Float may be undefined, or defined from star imports
(F405)
9839-9839: transformation may be undefined, or defined from star imports
(F405)
9839-9839: Float may be undefined, or defined from star imports
(F405)
9839-9839: transformation may be undefined, or defined from star imports
(F405)
9839-9839: Float may be undefined, or defined from star imports
(F405)
9840-9840: transformation may be undefined, or defined from star imports
(F405)
9840-9840: Float may be undefined, or defined from star imports
(F405)
10035-10035: quaternion may be undefined, or defined from star imports
(F405)
10035-10035: Float may be undefined, or defined from star imports
(F405)
10035-10035: Scalar may be undefined, or defined from star imports
(F405)
10036-10036: quaternion may be undefined, or defined from star imports
(F405)
10036-10036: Float may be undefined, or defined from star imports
(F405)
10042-10042: Scalar may be undefined, or defined from star imports
(F405)
10042-10042: quaternion may be undefined, or defined from star imports
(F405)
10042-10042: Float may be undefined, or defined from star imports
(F405)
10043-10043: quaternion may be undefined, or defined from star imports
(F405)
10043-10043: Float may be undefined, or defined from star imports
(F405)
10049-10049: quaternion may be undefined, or defined from star imports
(F405)
10049-10049: Float may be undefined, or defined from star imports
(F405)
10049-10049: quaternion may be undefined, or defined from star imports
(F405)
10049-10049: Float may be undefined, or defined from star imports
(F405)
10050-10050: quaternion may be undefined, or defined from star imports
(F405)
10050-10050: Float may be undefined, or defined from star imports
(F405)
10163-10163: transformation may be undefined, or defined from star imports
(F405)
10163-10163: Float may be undefined, or defined from star imports
(F405)
10163-10163: transformation may be undefined, or defined from star imports
(F405)
10163-10163: Float may be undefined, or defined from star imports
(F405)
10164-10164: transformation may be undefined, or defined from star imports
(F405)
10164-10164: Float may be undefined, or defined from star imports
(F405)
10170-10170: Scalar may be undefined, or defined from star imports
(F405)
10170-10170: transformation may be undefined, or defined from star imports
(F405)
10170-10170: Float may be undefined, or defined from star imports
(F405)
10171-10171: transformation may be undefined, or defined from star imports
(F405)
10171-10171: Float may be undefined, or defined from star imports
(F405)
10177-10177: transformation may be undefined, or defined from star imports
(F405)
10177-10177: Float may be undefined, or defined from star imports
(F405)
10177-10177: Scalar may be undefined, or defined from star imports
(F405)
10178-10178: transformation may be undefined, or defined from star imports
(F405)
10178-10178: Float may be undefined, or defined from star imports
(F405)
10238-10238: quaternion may be undefined, or defined from star imports
(F405)
10238-10238: Float may be undefined, or defined from star imports
(F405)
10238-10238: Scalar may be undefined, or defined from star imports
(F405)
10239-10239: quaternion may be undefined, or defined from star imports
(F405)
10239-10239: Float may be undefined, or defined from star imports
(F405)
10245-10245: Scalar may be undefined, or defined from star imports
(F405)
10245-10245: quaternion may be undefined, or defined from star imports
(F405)
10245-10245: Float may be undefined, or defined from star imports
(F405)
10246-10246: quaternion may be undefined, or defined from star imports
(F405)
10246-10246: Float may be undefined, or defined from star imports
(F405)
10270-10270: quaternion may be undefined, or defined from star imports
(F405)
10270-10270: Float may be undefined, or defined from star imports
(F405)
10271-10271: quaternion may be undefined, or defined from star imports
(F405)
10271-10271: Float may be undefined, or defined from star imports
(F405)
10292-10292: quaternion may be undefined, or defined from star imports
(F405)
10292-10292: Float may be undefined, or defined from star imports
(F405)
10293-10293: quaternion may be undefined, or defined from star imports
(F405)
10293-10293: Float may be undefined, or defined from star imports
(F405)
11765-11765: quaternion may be undefined, or defined from star imports
(F405)
11765-11765: Float may be undefined, or defined from star imports
(F405)
⏰ 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). (6)
- GitHub Check: ci / test-warp (windows-2025, windows)
- GitHub Check: ci / test-warp (ubuntu-24.04, ubuntu-x86_64)
- GitHub Check: ci / test-warp (ubuntu-24.04-arm, ubuntu-aarch64)
- GitHub Check: ci / build-docs
- GitHub Check: ci / test-warp (macos-latest, macos)
- GitHub Check: cppcheck
🔇 Additional comments (17)
docs/_templates/builtins.rst (1)
20-20: LGTM! Docstring indentation fix applied correctly.Adding
first=Trueensures the first line of multi-line docstrings is also indented, producing consistent margins within RST function directives.docs/language_reference/builtins.rst (1)
319-349: LGTM! Documentation reorganization improves structure.The Utility section is logically placed after Random and before Other. The included items are appropriate for a utility category, and the format is consistent with other sections. The new
block_dimbuiltin mentioned in the PR objectives is properly documented here.warp/_src/types.py (4)
63-126: LGTM: Forward reference tois_arrayis safe due to Python's late binding.The
scalar_baseclass usesis_array(y)in arithmetic methods to delegate to array operations when the operand is an array. Since Python resolves names at call time (not definition time), andis_arrayis defined in this same module before any scalar operations can occur, this works correctly.The pattern of returning
NotImplementedwhen the operand is an array allows proper delegation to the array's reflected methods (e.g.,__radd__).
147-168: LGTM: Custombooltype correctly shadows the builtin.The custom
boolclass intentionally shadows Python's built-inboolwithin this module. The code correctly usesbuiltins.boolfor return type annotations (e.g., line 67, 154) to distinguish between the Warp type and Python's native boolean. The class appropriately does not inherit fromscalar_basesince boolean arithmetic operations aren't semantically meaningful in this context.
170-223: LGTM: Concrete scalar type hierarchy is well-structured.The scalar types are correctly defined with:
- Appropriate inheritance (
float_basefor floats,int_basefor integers)- Consistent
_length_ = 1for scalar indication- Correct ctypes mappings for each type
float16correctly usingctypes.c_uint16for half-precision bit storage
225-253: LGTM: TypeVars with explicit constraints align with Pyright requirements.The scalar type tuples provide a canonical source of truth, and the TypeVars are correctly defined with explicit constraints as required by Pyright (which doesn't support tuple unpacking in TypeVar definitions). Including both Python builtins (
int,float,builtins.bool) and Warp types ensures proper type inference across the codebase.The comment on line 232-233 is helpful for future maintainers when adding new scalar types.
warp/__init__.pyi (6)
2004-2011: Quaternion type parameter corrections look correct.The change from
Quaternion[Scalar]toQuaternion[Float]aligns with the type definition inwarp/_src/types.pywhereQuaternionis defined asGeneric[Float]. This ensures type consistency across the codebase.Also applies to: 2040-2047, 2076-2083
2143-2146: Consistent type update forlength_sq.The return type
Floatis appropriate since the squared length of aQuaternion[Float]naturally produces aFloatresult.
4571-4587: Consolidatedtid()signature with union return type is acceptable.The merge of multiple overloads into a single signature with a union return type follows the PR's approach for handling overloads with identical input types. The docstring clearly documents the unpacking-based behavior.
Note that Python type checkers cannot infer the specific return type based on unpacking syntax (e.g.,
i, j = wp.tid()will still type as the full union). This is a known limitation, but acceptable given:
- This is primarily for IDE autocomplete
- Warp's codegen handles the actual dispatch
- Separate no-argument overloads would conflict anyway
5699-5711: Arithmetic operations correctly useFloattype parameter.The
addandsuboverloads forQuaternion[Float]andTransformation[Float]are consistent with the generic type definitions.Also applies to: 5734-5742
5869-5921: Multiplication, division, and unary operations are correctly typed.The mixed-type operations (e.g.,
Quaternion[Float] * Scalar) appropriately useScalarfor the scalar operand while maintainingFloatfor the quaternion/transformation types. This correctly models scalar multiplication on Float-parameterized types.Also applies to: 5969-5976, 5993-5996, 6013-6016
6302-6304:lenoverload for Quaternion is correctly typed.warp/_src/builtins.py (5)
427-437: Quaternion predicates now correctly constrain dtype toFloat.Switching
isfinite/isnan/isinfquaternion overloads toquaternion(dtype=Float)aligns with the “no integers” direction and avoids oddScalarquaternions showing up in stubs.Also applies to: 475-486, 524-535
742-747:length_sq(quaternion)returning Float-precision is consistent withlength(quaternion).Using
float_sametypes_value_funchere looks right for quaternion-only float dtypes and keeps return-type inference consistent.
6925-6935: Hidingreversed(range_t)matches the “don’t expose built-in reversed” objective.
hidden=True+export=Falseshould keep it out of generated stubs/docs while preserving internal availability.
7726-7735: Native binding and codegen wiring are properly implemented.The C++ implementation exists in
warp/native/exports.h(line 1102) and is wired through codegen via macros inwarp/_src/codegen.py. Theblock_dim=parameter in launch APIs uses a different naming context, so no collision occurs.
7629-7724: Thetid()stub correctly includes all return types, includingint.The generated
.pyistub file definestid()with the return typeint | tuple[int, int] | tuple[int, int, int] | tuple[int, int, int, int], confirming that theexport=Falseflag on thevalue_type=intoverload does not prevent the plainintreturn case from being included in the merged stub. The stub generation properly handles the union of all overloads.
Greptile OverviewGreptile SummaryThis PR successfully resolves Pyright type checker warnings and enables strict validation in CI/CD pipelines. The changes address four key areas: 1. Hidden 2. Fixed RST docstring indentation - Applied Jinja's 3. Merged overlapping
4. Enabled strict CI/CD validation - Removed All changes are well-structured with proper error handling (exception catching in Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Build as build_lib.py
participant Context as context.py::export_stubs()
participant Builtins as builtins.py
participant Stubs as __init__.pyi
participant CI as CI/CD Pyright
Dev->>Builtins: Define wp.tid() overloads (1D-4D)
Dev->>Builtins: Mark reversed as hidden=True
Dev->>Builtins: Fix quaternion types (Scalar→Float)
Build->>Context: Call export_stubs()
Context->>Builtins: Read builtin_functions
Note over Context: Check overloads with<br/>identical input_types
Context->>Context: Detect wp.tid() has same<br/>input_types ({}) across 4 overloads
Context->>Context: Call add_merged_builtin_function_stub()
Context->>Context: Generate union return type:<br/>int | tuple[int,int] | ...
Context->>Stubs: Write merged wp.tid() signature
Context->>Stubs: Skip reversed (hidden=True)
Context->>Stubs: Write Quaternion[Float] types
Stubs->>CI: Validate with Pyright
alt Validation passes
CI->>Dev: ✓ Build succeeds
else Validation fails
CI->>Dev: ✗ Build fails (no allow_failure)
end
|
|
Reminding myself of a concern that CodeRabbit raised and is worth looking more into tomorrow:
|
d8e40aa to
b0e1f18
Compare
There was a problem hiding this comment.
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)
warp/_src/types.py (1)
2251-2254: Potential typing/runtime mismatch in scalars_equal_generic.Lines 2251-2254 check
scalar_and_bool_types(which includesbool) when matching againstScalar, but theScalarTypeVar (lines 236-251) explicitly excludesbool. This creates an inconsistency:
- Static typing:
boolis not a validScalar(TypeVar excludes it)- scalars_equal_generic:
boolmatchesScalar(usesscalar_and_bool_types)This could cause confusing behavior where code passes runtime checks but fails static type checking, or vice versa.
Consider updating to use
scalar_typesinstead ofscalar_and_bool_typesfor consistency with theScalarTypeVar definition, or document this as intentional behavior.- if a is Scalar and b in scalar_and_bool_types: + if a is Scalar and b in scalar_types: return True - if b is Scalar and a in scalar_and_bool_types: + if b is Scalar and a in scalar_types: return Truewarp/_src/builtins.py (1)
7635-7724: Thebuiltin_tid{1,2,3,4}dsymbols are properly defined; verify documentation covers excess unpacking.The native function symbols exist as C++ macros in
warp/_src/codegen.py. However, the docstring should clarify what happens when callers unpack more indices than the launch dimensionality: excess indices return0. For example, callingi, j = wp.tid()on a 1D launch will return(i_actual, 0).warp/_src/context.py (1)
8919-8941: Merge-detection should preserve parameter order (don’t sortinput_types.items()).
tuple(sorted(f.input_types.items()))can treat overloads with the same keys/types but different parameter order as identical, then emit a merged stub using the first overload’s order. Since order matters for signatures, comparingtuple(f.input_types.items())directly is safer and simpler.Proposed fix
- first_inputs = tuple(sorted(first.input_types.items())) + first_inputs = tuple(first.input_types.items()) all_same_inputs = all( - tuple(sorted(f.input_types.items())) == first_inputs for f in non_hidden_overloads + tuple(f.input_types.items()) == first_inputs for f in non_hidden_overloads )
🤖 Fix all issues with AI agents
In @warp/_src/builtins.py:
- Around line 7726-7735: The docstring for the block_dim builtin is too minimal
and should state kernel-context restrictions like tid() does; update the
"block_dim" builtin registration so its doc string (for the builtin named
"block_dim" mapped to native_func "builtin_block_dim") includes whether it may
or may not be called from user-defined Warp functions or only inside
kernels—mirror tid()'s phrasing if the same restriction applies, or explicitly
document any difference in allowed usage and context.
- Around line 10033-10053: The scalar_mul_create_value_func currently uses
next(...) over scalar_types (which excludes bool) and can raise StopIteration
when type matching allowed bool via scalar_and_bool_types; change the next(...)
call inside scalar_mul_create_value_func to supply a sentinel default (e.g.,
None) and then explicitly raise a clear RuntimeError if the result is the
sentinel, so you return a controlled error instead of letting StopIteration
propagate; ensure the error message references the offending input types and
keep the rest of the matching logic unchanged.
In @warp/_src/context.py:
- Around line 8657-8664: The function get_return_type_str calls
f.value_func(None, None) unsafely which can raise and abort stub generation;
change it to first try calling f.value_func with f.input_types (e.g.,
f.value_func(f.input_types, None)) if available, and wrap the call in a
try/except that falls back to using f.value_type (or None) on any exception;
ensure you still convert a resolved return_type via type_str before returning.
In @warp/_src/types.py:
- Around line 225-251: The runtime matching in scalars_equal_generic incorrectly
treats bool as a valid match for the TypeVar Scalar; update the matching logic
so it uses scalar_types (which excludes bool) instead of scalar_and_bool_types
when checking "if a is Scalar and b in ..." and "if b is Scalar and a in ...",
ensuring runtime behavior matches the Scalar TypeVar, or alternatively add bool
to the Scalar TypeVar declaration if you intend bool to be a valid Scalar—prefer
the first option to preserve the current static typing contract.
🧹 Nitpick comments (4)
warp/_src/builtins.py (2)
10161-10181: Transformationmuloverloads updated to Float — good; sameScalar/boolhazard applies to scalar multiply.
IfScalarcan matchbool, the samescalar_mul_create_value_func()StopIteration risk exists forScalar * transformationandtransformation * Scalar.
10236-10249: Quaterniondivoverloads updated to Float — good; sameScalar/boolhazard applies.warp/_src/context.py (2)
8666-8679: Consider_builtins.boolnormalization for builtin stubs (avoidwarp.boolshadowing).You already import
builtins as _builtinsand normalizeboolinformat_annotation(), but builtin stub emission usestype_str()directly, which can emitbooland end up referring towarp.boolin the stub module (not Python’sbool). If Pyright is treating these stubs as the public surface, this can create avoidable typing friction.Suggestion: apply the same
re.sub(r"\bbool\b", "_builtins.bool", ...)normalization toargsandreturn_str(or introduce astub_type_str()wrapper used only by stub generation).
(confirm desired semantics: should stub signatures accept_builtins.boolorwarp.bool?)
8681-8713: Merged return type uses|: verify supported Python/Pyright target, or emitUnion[...].
return_str = " -> " + " | ".join(return_types)is great for readability, but it assumes PEP 604 unions are valid for the configured type-checking target. If the project still supports Python < 3.10 for type checking, this will break parsing.Options:
- Ensure Pyright config targets 3.10+ for stubs, or
- Emit
Union[...](and addfrom typing import Unionin the stub header), or- Emit
typing_extensions.TypeAlias/compat strategy if needed.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.github/workflows/ci.yml.gitlab-ci.ymlwarp/__init__.pyiwarp/_src/builtins.pywarp/_src/context.pywarp/_src/types.py
💤 Files with no reviewable changes (2)
- .gitlab-ci.yml
- .github/workflows/ci.yml
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1167
File: warp/tests/test_static.py:776-781
Timestamp: 2026-01-13T06:46:08.692Z
Learning: In the NVIDIA/warp repository, star imports like `from warp.tests.unittest_utils import *` in test files are acceptable per the project's Ruff configuration, and F405 warnings should not be flagged if pre-commit checks pass.
🧬 Code graph analysis (3)
warp/_src/types.py (2)
exts/omni.warp/omni/warp/nodes/_impl/kernel.py (1)
is_array(254-255)warp/__init__.pyi (12)
add(5689-5691)add(5694-5696)add(5699-5701)add(5704-5706)add(5709-5711)add(5714-5716)sub(5719-5721)sub(5724-5726)sub(5729-5731)sub(5734-5736)sub(5739-5741)sub(5744-5746)
warp/__init__.pyi (6)
warp/native/crt.h (3)
isfinite(341-341)isnan(343-343)isinf(345-345)warp/_src/types.py (2)
Quaternion(262-263)Transformation(266-267)warp/native/tile.h (1)
len(1757-1760)warp/native/array.h (1)
len(2218-2218)warp/native/mat.h (1)
len(5516-5519)warp/native/vec.h (1)
len(2264-2264)
warp/_src/builtins.py (2)
warp/__init__.pyi (6)
quaternion(2332-2336)quaternion(2339-2341)quaternion(2344-2346)quaternion(2349-2351)transformation(2412-2414)transformation(2417-2419)warp/_src/types.py (3)
quaternion(1222-1235)dtype(4972-4978)transformation(1250-1327)
🪛 Ruff (0.14.10)
warp/_src/builtins.py
428-428: quaternion may be undefined, or defined from star imports
(F405)
428-428: Float may be undefined, or defined from star imports
(F405)
477-477: quaternion may be undefined, or defined from star imports
(F405)
477-477: Float may be undefined, or defined from star imports
(F405)
526-526: quaternion may be undefined, or defined from star imports
(F405)
526-526: Float may be undefined, or defined from star imports
(F405)
743-743: quaternion may be undefined, or defined from star imports
(F405)
743-743: Float may be undefined, or defined from star imports
(F405)
8829-8829: quaternion may be undefined, or defined from star imports
(F405)
8829-8829: Float may be undefined, or defined from star imports
(F405)
8838-8838: transformation may be undefined, or defined from star imports
(F405)
8838-8838: Float may be undefined, or defined from star imports
(F405)
9065-9065: quaternion may be undefined, or defined from star imports
(F405)
9065-9065: Float may be undefined, or defined from star imports
(F405)
9075-9075: transformation may be undefined, or defined from star imports
(F405)
9075-9075: Float may be undefined, or defined from star imports
(F405)
9103-9103: quaternion may be undefined, or defined from star imports
(F405)
9103-9103: Float may be undefined, or defined from star imports
(F405)
9114-9114: transformation may be undefined, or defined from star imports
(F405)
9114-9114: Float may be undefined, or defined from star imports
(F405)
9136-9136: quaternion may be undefined, or defined from star imports
(F405)
9136-9136: Float may be undefined, or defined from star imports
(F405)
9179-9179: quaternion may be undefined, or defined from star imports
(F405)
9179-9179: Float may be undefined, or defined from star imports
(F405)
9790-9790: quaternion may be undefined, or defined from star imports
(F405)
9790-9790: Float may be undefined, or defined from star imports
(F405)
9790-9790: quaternion may be undefined, or defined from star imports
(F405)
9790-9790: Float may be undefined, or defined from star imports
(F405)
9791-9791: quaternion may be undefined, or defined from star imports
(F405)
9791-9791: Float may be undefined, or defined from star imports
(F405)
9805-9805: transformation may be undefined, or defined from star imports
(F405)
9805-9805: Float may be undefined, or defined from star imports
(F405)
9805-9805: transformation may be undefined, or defined from star imports
(F405)
9805-9805: Float may be undefined, or defined from star imports
(F405)
9806-9806: transformation may be undefined, or defined from star imports
(F405)
9806-9806: Float may be undefined, or defined from star imports
(F405)
9832-9832: quaternion may be undefined, or defined from star imports
(F405)
9832-9832: Float may be undefined, or defined from star imports
(F405)
9832-9832: quaternion may be undefined, or defined from star imports
(F405)
9832-9832: Float may be undefined, or defined from star imports
(F405)
9833-9833: quaternion may be undefined, or defined from star imports
(F405)
9833-9833: Float may be undefined, or defined from star imports
(F405)
9839-9839: transformation may be undefined, or defined from star imports
(F405)
9839-9839: Float may be undefined, or defined from star imports
(F405)
9839-9839: transformation may be undefined, or defined from star imports
(F405)
9839-9839: Float may be undefined, or defined from star imports
(F405)
9840-9840: transformation may be undefined, or defined from star imports
(F405)
9840-9840: Float may be undefined, or defined from star imports
(F405)
10035-10035: quaternion may be undefined, or defined from star imports
(F405)
10035-10035: Float may be undefined, or defined from star imports
(F405)
10035-10035: Scalar may be undefined, or defined from star imports
(F405)
10036-10036: quaternion may be undefined, or defined from star imports
(F405)
10036-10036: Float may be undefined, or defined from star imports
(F405)
10042-10042: Scalar may be undefined, or defined from star imports
(F405)
10042-10042: quaternion may be undefined, or defined from star imports
(F405)
10042-10042: Float may be undefined, or defined from star imports
(F405)
10043-10043: quaternion may be undefined, or defined from star imports
(F405)
10043-10043: Float may be undefined, or defined from star imports
(F405)
10049-10049: quaternion may be undefined, or defined from star imports
(F405)
10049-10049: Float may be undefined, or defined from star imports
(F405)
10049-10049: quaternion may be undefined, or defined from star imports
(F405)
10049-10049: Float may be undefined, or defined from star imports
(F405)
10050-10050: quaternion may be undefined, or defined from star imports
(F405)
10050-10050: Float may be undefined, or defined from star imports
(F405)
10163-10163: transformation may be undefined, or defined from star imports
(F405)
10163-10163: Float may be undefined, or defined from star imports
(F405)
10163-10163: transformation may be undefined, or defined from star imports
(F405)
10163-10163: Float may be undefined, or defined from star imports
(F405)
10164-10164: transformation may be undefined, or defined from star imports
(F405)
10164-10164: Float may be undefined, or defined from star imports
(F405)
10170-10170: Scalar may be undefined, or defined from star imports
(F405)
10170-10170: transformation may be undefined, or defined from star imports
(F405)
10170-10170: Float may be undefined, or defined from star imports
(F405)
10171-10171: transformation may be undefined, or defined from star imports
(F405)
10171-10171: Float may be undefined, or defined from star imports
(F405)
10177-10177: transformation may be undefined, or defined from star imports
(F405)
10177-10177: Float may be undefined, or defined from star imports
(F405)
10177-10177: Scalar may be undefined, or defined from star imports
(F405)
10178-10178: transformation may be undefined, or defined from star imports
(F405)
10178-10178: Float may be undefined, or defined from star imports
(F405)
10238-10238: quaternion may be undefined, or defined from star imports
(F405)
10238-10238: Float may be undefined, or defined from star imports
(F405)
10238-10238: Scalar may be undefined, or defined from star imports
(F405)
10239-10239: quaternion may be undefined, or defined from star imports
(F405)
10239-10239: Float may be undefined, or defined from star imports
(F405)
10245-10245: Scalar may be undefined, or defined from star imports
(F405)
10245-10245: quaternion may be undefined, or defined from star imports
(F405)
10245-10245: Float may be undefined, or defined from star imports
(F405)
10246-10246: quaternion may be undefined, or defined from star imports
(F405)
10246-10246: Float may be undefined, or defined from star imports
(F405)
10270-10270: quaternion may be undefined, or defined from star imports
(F405)
10270-10270: Float may be undefined, or defined from star imports
(F405)
10271-10271: quaternion may be undefined, or defined from star imports
(F405)
10271-10271: Float may be undefined, or defined from star imports
(F405)
10292-10292: quaternion may be undefined, or defined from star imports
(F405)
10292-10292: Float may be undefined, or defined from star imports
(F405)
10293-10293: quaternion may be undefined, or defined from star imports
(F405)
10293-10293: Float may be undefined, or defined from star imports
(F405)
11765-11765: quaternion may be undefined, or defined from star imports
(F405)
11765-11765: Float may be undefined, or defined from star imports
(F405)
🔇 Additional comments (25)
warp/_src/types.py (6)
63-126: LGTM - Well-structured scalar base class.The
scalar_baseclass provides a clean foundation for the scalar type hierarchy. The arithmetic operations correctly returnNotImplementedwhen the other operand is an array, allowing Python's operator dispatch to handle mixed-type operations properly.
128-145: LGTM - Proper intermediate base classes.The
float_baseandint_baseclasses appropriately extendscalar_basewith type-specific behavior. The__index__method inint_basecorrectly uses ctypes conversion for proper integer truncation semantics.
147-168: LGTM - Intentional design for bool type.The
boolclass intentionally does not inherit fromscalar_base, which prevents arithmetic operations on boolean values. This is appropriate since boolean arithmetic semantics differ from numeric scalars. The class correctly shadowsbuiltins.bool, and the code consistently usesbuiltins.boolwhere Python's native bool type is needed.
170-223: LGTM - Consistent scalar type definitions.The concrete scalar types correctly inherit from their respective base classes and define appropriate ctypes mappings. The use of
ctypes.c_uint16forfloat16is correct since half-precision floats are stored as their bit representation.
2148-2153: LGTM - Correct value type handling.The
value_typestuple appropriately includes both Python'sbuiltins.booland Warp'sbooltype throughscalar_and_bool_types, ensuring proper value detection at runtime.
5920-5927: LGTM - Consistent Scalar template matching.The
type_matches_templatefunction correctly checksarg_type in scalar_typesforScalartemplate types, which is consistent with theScalarTypeVar definition that excludesbool.warp/_src/builtins.py (15)
427-437: Quaternionisfinite()overload toquaternion(dtype=Float)looks consistent with “float-only” direction.
This aligns the quaternion overload with the deprecation messaging about integer inputs.
475-486: Quaternionisnan()overload toquaternion(dtype=Float)looks consistent.
524-535: Quaternionisinf()overload toquaternion(dtype=Float)looks consistent.
742-747:length_sq()quaternion overload switching to Float + float-type inference is correct.
Usingfloat_sametypes_value_funchere matches the “quaternion is float-like” model and avoids integer return typing.
6925-6935: Hidingreversedfrom stubs/docs is sensible (matchesrange/iter_nexttreatment).
8828-8844: Updatingextract()overloads toquaternion(dtype=Float)/transformation(dtype=Float)is consistent with the new typing model.
9063-9081:assign_inplaceoverloads for quaternion/transformation updated consistently to Float.
9100-9120:assign_copyoverloads for quaternion/transformation updated consistently to Float.
9133-9142:add_inplacequaternion overload updated consistently to Float.
9176-9185:sub_inplacequaternion overload updated consistently to Float.
9776-9809: Operatoraddoverloads updated to Float for quaternion/transformation — looks correct.
9811-9843: Operatorsuboverloads updated to Float for quaternion/transformation — looks correct.
10268-10274: Unaryposquaternion overload updated to Float — looks correct.
10290-10296: Unarynegquaternion overload updated to Float — looks correct.
11763-11771:len(quaternion)overload updated to Float — looks correct.warp/__init__.pyi (4)
2004-2011: Type parameter correction looks good.The change from
Quaternion[Scalar]toQuaternion[Float]forisfinite,isnan,isinf, andlength_sqcorrectly aligns with theQuaternionclass definition (Generic[Float]) intypes.py. These mathematical operations are only meaningful for floating-point types.Also applies to: 2040-2047, 2076-2083, 2143-2146
4571-4587: Consolidated tid() signature with clear documentation.The merged overload using a union return type effectively communicates the function's behavior. The docstring clearly explains how the return type depends on the unpacking syntax used at the call site, which is helpful for users understanding the dynamic nature of this kernel intrinsic.
5699-5700: Quaternion arithmetic operators correctly updated to Float.The quaternion arithmetic operations now consistently use
Quaternion[Float], matching the generic class definition. The scalar operands inmulanddivappropriately remainScalarto allow numeric flexibility while ensuring the quaternion container type is constrained to floating-point.Also applies to: 5734-5735, 5869-5880, 5969-5975, 5993-5994, 6013-6014
5709-5710: Transformation and len() changes are consistent.The
Transformationoperations andlen()overload for quaternions are correctly updated to useFloat, consistent with their generic class definitions intypes.py.Also applies to: 5739-5740, 5909-5920, 6302-6303
- Unify wp.tid() docstrings across all overloads in builtins.py - Add add_merged_builtin_function_stub() to detect and merge overloads with identical input_types into a single stub with union return type - Fix quaternion type parameters for isfinite/isnan/isinf/length_sq (Scalar -> Float) - Refactor scalar type definitions in types.py for earlier availability Resolves type checker warnings about overlapping function signatures where return type depends on usage context rather than input parameters. Signed-off-by: Eric Shi <ershi@nvidia.com>
Signed-off-by: Eric Shi <ershi@nvidia.com>
Use scalar_types instead of scalar_and_bool_types when matching the Scalar TypeVar in types_match(). This aligns with type_matches_template() and prevents potential StopIteration crashes in value_func helpers like scalar_mul_create_value_func() that search only scalar_types. Signed-off-by: Eric Shi <ershi@nvidia.com>
b0e1f18 to
ac40cec
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
warp/_src/builtins.py (1)
7628-7724: Add test coverage fortid()kernel-only enforcement andblock_dim()in user functions.The compiler correctly enforces that
tid()cannot be called from user-defined Warp functions viacheck_tid_in_func_error()incodegen.py(lines 2607–2613), andblock_dim()is properly registered as a public builtin with no such restrictions. However, test coverage explicitly verifying this distinction is missing—add tests confirmingtid()raisesWarpCodegenErrorwhen called in@wp.funcandblock_dim()works correctly in user-defined functions.
🧹 Nitpick comments (2)
warp/_src/context.py (2)
8922-8937: Don’t ignore parameter order when deciding “identical input_types” merges.The merge predicate uses
tuple(sorted(f.input_types.items())), which treats the same params in a different order as “identical”. But order is part of the effective signature (and Warp’sFunction.signatureis built frominput_types.keys()order). Safer: comparetuple(f.input_types.items())directly (order-preserving), so you only merge truly identical signatures.Proposed diff
first = non_hidden_overloads[0] - first_inputs = tuple(sorted(first.input_types.items())) - all_same_inputs = all( - tuple(sorted(f.input_types.items())) == first_inputs for f in non_hidden_overloads - ) + first_inputs = tuple(first.input_types.items()) + all_same_inputs = all(tuple(f.input_types.items()) == first_inputs for f in non_hidden_overloads) if all_same_inputs: add_merged_builtin_function_stub(non_hidden_overloads) continueAlso applies to: 8938-8942
8682-8714: PEP 604 union syntax is currently compatible with your Pyright setup; however, consider explicitly settingpythonVersionif 3.9 type-checking support is desired.The code uses
" | ".join(return_types)which generates PEP 604 syntax (A | B). While this is only valid in Python 3.10+, Pyright currently has no explicitpythonVersionconfigured inpyproject.toml, so it infers from the running Python version in CI (3.11+) and will accept this syntax.However, since the project declares
requires-python = ">=3.9", if you want strict type-checking compatibility with Python 3.9, addpythonVersion = "3.10"(or higher) to the[tool.pyright]section, or switch toUnion[...]syntax withfrom typing import Unionin the stub header for broader 3.9 compatibility.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.github/workflows/ci.yml.gitlab-ci.ymlwarp/__init__.pyiwarp/_src/builtins.pywarp/_src/context.pywarp/_src/types.py
💤 Files with no reviewable changes (2)
- .gitlab-ci.yml
- .github/workflows/ci.yml
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1167
File: warp/tests/test_static.py:776-781
Timestamp: 2026-01-13T06:46:08.692Z
Learning: In the NVIDIA/warp repository, star imports like `from warp.tests.unittest_utils import *` in test files are acceptable per the project's Ruff configuration, and F405 warnings should not be flagged if pre-commit checks pass.
📚 Learning: 2026-01-13T17:29:07.264Z
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1171
File: warp/_src/builtins.py:7726-7735
Timestamp: 2026-01-13T17:29:07.264Z
Learning: In warp/_src/builtins.py (NVIDIA/warp), enforce that block_dim() may be called from user-defined Warp functions, while tid() is kernel-only and must not be called from Warp function bodies. Ensure the builtins registration and related usage enforce this distinction, and add tests to verify allowed vs disallowed calls in user-defined Warp functions.
Applied to files:
warp/_src/builtins.py
📚 Learning: 2025-09-28T18:45:45.955Z
Learnt from: StafaH
Repo: NVIDIA/warp PR: 925
File: warp/native/bvh.h:359-369
Timestamp: 2025-09-28T18:45:45.955Z
Learning: StafaH prefers to defer the BVH shared stack stride issue (hardcoded WP_BVH_BLOCK_DIM vs runtime blockDim.x) for a future update rather than implementing the dynamic shared memory solution now.
Applied to files:
warp/_src/builtins.py
📚 Learning: 2026-01-13T17:29:07.264Z
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1171
File: warp/_src/builtins.py:7726-7735
Timestamp: 2026-01-13T17:29:07.264Z
Learning: In NVIDIA/warp (PR #1171), block_dim() may be called from user-defined Warp functions, while tid() may not; tid() is kernel-only. File context: warp/_src/builtins.py builtins registration.
Applied to files:
warp/__init__.pyi
🧬 Code graph analysis (4)
warp/_src/context.py (1)
warp/_src/utils.py (1)
warn(70-84)
warp/_src/types.py (2)
exts/omni.warp/omni/warp/nodes/_impl/kernel.py (1)
is_array(254-255)warp/__init__.pyi (12)
add(5689-5691)add(5694-5696)add(5699-5701)add(5704-5706)add(5709-5711)add(5714-5716)sub(5719-5721)sub(5724-5726)sub(5729-5731)sub(5734-5736)sub(5739-5741)sub(5744-5746)
warp/_src/builtins.py (2)
warp/_src/types.py (5)
quaternion(1222-1235)dtype(4972-4978)vector(527-736)transformation(1250-1327)matrix(740-1160)warp/__init__.pyi (11)
quaternion(2332-2336)quaternion(2339-2341)quaternion(2344-2346)quaternion(2349-2351)vector(2224-2226)length(2129-2131)length(2134-2136)transformation(2412-2414)transformation(2417-2419)matrix(2229-2240)matrix(2243-2245)
warp/__init__.pyi (2)
warp/_src/types.py (6)
dtype(4972-4978)Array(270-360)Quaternion(262-263)Vector(254-255)Transformation(266-267)Tile(363-364)warp/native/vec.h (1)
expect_near(1295-1312)
🪛 Ruff (0.14.11)
warp/_src/context.py
8663-8664: try-except-pass detected, consider logging the exception
(S110)
8663-8663: Do not catch blind exception: Exception
(BLE001)
warp/_src/builtins.py
428-428: quaternion may be undefined, or defined from star imports
(F405)
428-428: Float may be undefined, or defined from star imports
(F405)
477-477: quaternion may be undefined, or defined from star imports
(F405)
477-477: Float may be undefined, or defined from star imports
(F405)
526-526: quaternion may be undefined, or defined from star imports
(F405)
526-526: Float may be undefined, or defined from star imports
(F405)
743-743: quaternion may be undefined, or defined from star imports
(F405)
743-743: Float may be undefined, or defined from star imports
(F405)
8830-8830: vector may be undefined, or defined from star imports
(F405)
8839-8839: quaternion may be undefined, or defined from star imports
(F405)
8839-8839: Float may be undefined, or defined from star imports
(F405)
8848-8848: transformation may be undefined, or defined from star imports
(F405)
8848-8848: Float may be undefined, or defined from star imports
(F405)
8921-8921: matrix may be undefined, or defined from star imports
(F405)
8930-8930: matrix may be undefined, or defined from star imports
(F405)
8981-8981: vector may be undefined, or defined from star imports
(F405)
9025-9025: vector may be undefined, or defined from star imports
(F405)
9047-9047: matrix may be undefined, or defined from star imports
(F405)
9127-9127: quaternion may be undefined, or defined from star imports
(F405)
9127-9127: Float may be undefined, or defined from star imports
(F405)
9137-9137: transformation may be undefined, or defined from star imports
(F405)
9137-9137: Float may be undefined, or defined from star imports
(F405)
9165-9165: quaternion may be undefined, or defined from star imports
(F405)
9165-9165: Float may be undefined, or defined from star imports
(F405)
9176-9176: transformation may be undefined, or defined from star imports
(F405)
9176-9176: Float may be undefined, or defined from star imports
(F405)
9198-9198: quaternion may be undefined, or defined from star imports
(F405)
9198-9198: Float may be undefined, or defined from star imports
(F405)
9241-9241: quaternion may be undefined, or defined from star imports
(F405)
9241-9241: Float may be undefined, or defined from star imports
(F405)
9694-9694: vector may be undefined, or defined from star imports
(F405)
9694-9694: vector may be undefined, or defined from star imports
(F405)
9704-9704: vector may be undefined, or defined from star imports
(F405)
9704-9704: vector may be undefined, or defined from star imports
(F405)
9715-9715: matrix may be undefined, or defined from star imports
(F405)
9715-9715: matrix may be undefined, or defined from star imports
(F405)
9725-9725: matrix may be undefined, or defined from star imports
(F405)
9725-9725: matrix may be undefined, or defined from star imports
(F405)
9896-9896: quaternion may be undefined, or defined from star imports
(F405)
9896-9896: Float may be undefined, or defined from star imports
(F405)
9896-9896: quaternion may be undefined, or defined from star imports
(F405)
9896-9896: Float may be undefined, or defined from star imports
(F405)
9897-9897: quaternion may be undefined, or defined from star imports
(F405)
9897-9897: Float may be undefined, or defined from star imports
(F405)
9911-9911: transformation may be undefined, or defined from star imports
(F405)
9911-9911: Float may be undefined, or defined from star imports
(F405)
9911-9911: transformation may be undefined, or defined from star imports
(F405)
9911-9911: Float may be undefined, or defined from star imports
(F405)
9912-9912: transformation may be undefined, or defined from star imports
(F405)
9912-9912: Float may be undefined, or defined from star imports
(F405)
9938-9938: quaternion may be undefined, or defined from star imports
(F405)
9938-9938: Float may be undefined, or defined from star imports
(F405)
9938-9938: quaternion may be undefined, or defined from star imports
(F405)
9938-9938: Float may be undefined, or defined from star imports
(F405)
9939-9939: quaternion may be undefined, or defined from star imports
(F405)
9939-9939: Float may be undefined, or defined from star imports
(F405)
9945-9945: transformation may be undefined, or defined from star imports
(F405)
9945-9945: Float may be undefined, or defined from star imports
(F405)
9945-9945: transformation may be undefined, or defined from star imports
(F405)
9945-9945: Float may be undefined, or defined from star imports
(F405)
9946-9946: transformation may be undefined, or defined from star imports
(F405)
9946-9946: Float may be undefined, or defined from star imports
(F405)
10141-10141: quaternion may be undefined, or defined from star imports
(F405)
10141-10141: Float may be undefined, or defined from star imports
(F405)
10141-10141: Scalar may be undefined, or defined from star imports
(F405)
10142-10142: quaternion may be undefined, or defined from star imports
(F405)
10142-10142: Float may be undefined, or defined from star imports
(F405)
10148-10148: Scalar may be undefined, or defined from star imports
(F405)
10148-10148: quaternion may be undefined, or defined from star imports
(F405)
10148-10148: Float may be undefined, or defined from star imports
(F405)
10149-10149: quaternion may be undefined, or defined from star imports
(F405)
10149-10149: Float may be undefined, or defined from star imports
(F405)
10155-10155: quaternion may be undefined, or defined from star imports
(F405)
10155-10155: Float may be undefined, or defined from star imports
(F405)
10155-10155: quaternion may be undefined, or defined from star imports
(F405)
10155-10155: Float may be undefined, or defined from star imports
(F405)
10156-10156: quaternion may be undefined, or defined from star imports
(F405)
10156-10156: Float may be undefined, or defined from star imports
(F405)
10269-10269: transformation may be undefined, or defined from star imports
(F405)
10269-10269: Float may be undefined, or defined from star imports
(F405)
10269-10269: transformation may be undefined, or defined from star imports
(F405)
10269-10269: Float may be undefined, or defined from star imports
(F405)
10270-10270: transformation may be undefined, or defined from star imports
(F405)
10270-10270: Float may be undefined, or defined from star imports
(F405)
10276-10276: Scalar may be undefined, or defined from star imports
(F405)
10276-10276: transformation may be undefined, or defined from star imports
(F405)
10276-10276: Float may be undefined, or defined from star imports
(F405)
10277-10277: transformation may be undefined, or defined from star imports
(F405)
10277-10277: Float may be undefined, or defined from star imports
(F405)
10283-10283: transformation may be undefined, or defined from star imports
(F405)
10283-10283: Float may be undefined, or defined from star imports
(F405)
10283-10283: Scalar may be undefined, or defined from star imports
(F405)
10284-10284: transformation may be undefined, or defined from star imports
(F405)
10284-10284: Float may be undefined, or defined from star imports
(F405)
10344-10344: quaternion may be undefined, or defined from star imports
(F405)
10344-10344: Float may be undefined, or defined from star imports
(F405)
10344-10344: Scalar may be undefined, or defined from star imports
(F405)
10345-10345: quaternion may be undefined, or defined from star imports
(F405)
10345-10345: Float may be undefined, or defined from star imports
(F405)
10351-10351: Scalar may be undefined, or defined from star imports
(F405)
10351-10351: quaternion may be undefined, or defined from star imports
(F405)
10351-10351: Float may be undefined, or defined from star imports
(F405)
10352-10352: quaternion may be undefined, or defined from star imports
(F405)
10352-10352: Float may be undefined, or defined from star imports
(F405)
10376-10376: quaternion may be undefined, or defined from star imports
(F405)
10376-10376: Float may be undefined, or defined from star imports
(F405)
10377-10377: quaternion may be undefined, or defined from star imports
(F405)
10377-10377: Float may be undefined, or defined from star imports
(F405)
10398-10398: quaternion may be undefined, or defined from star imports
(F405)
10398-10398: Float may be undefined, or defined from star imports
(F405)
10399-10399: quaternion may be undefined, or defined from star imports
(F405)
10399-10399: Float may be undefined, or defined from star imports
(F405)
11871-11871: quaternion may be undefined, or defined from star imports
(F405)
11871-11871: Float may be undefined, or defined from star imports
(F405)
⏰ 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). (5)
- GitHub Check: ci / test-warp (macos-latest, macos)
- GitHub Check: ci / test-warp (ubuntu-24.04, ubuntu-x86_64)
- GitHub Check: ci / test-warp (windows-2025, windows)
- GitHub Check: ci / test-warp (ubuntu-24.04-arm, ubuntu-aarch64)
- GitHub Check: ci / build-docs
🔇 Additional comments (19)
warp/_src/types.py (4)
63-145: LGTM - Well-designed base classes for scalar types.The
scalar_base,float_base, andint_basehierarchy properly handles:
- Arithmetic operator delegation to
warp.add,warp.sub, etc.- Correct
NotImplementedreturn for array operands to enable proper operator dispatch__index__implementation inint_basefor proper integer conversion through ctypes
147-168: LGTM - Bool class correctly excludes arithmetic operators.The
boolclass intentionally does not inherit fromscalar_base, which means it doesn't have arithmetic operators. This is semantically correct for boolean types and aligns with the separation ofscalar_types(without bool) andscalar_and_bool_types(with bool).
225-251: LGTM - Consistent type system definitions with good maintainability comments.The canonical tuple definitions (
int_types,float_types,scalar_types,scalar_and_bool_types) and corresponding TypeVars (Int,Float,Scalar) are now properly aligned:
ScalarTypeVar excludesbool, matchingscalar_types- Comment at lines 232-233 explicitly notes the need to keep TypeVars in sync with tuples
This addresses the typing vs runtime-dispatch consistency concern mentioned in PR comments.
2251-2256: LGTM - Runtime matching now consistent withScalarTypeVar definition.The change from
scalar_and_bool_typestoscalar_typesforScalarmatching ensures that runtime type dispatch aligns with the staticScalarTypeVar definition (which excludesbool). This resolves the typing vs runtime-dispatch mismatch noted in the PR comments.warp/_src/context.py (1)
8667-8680: Nice cleanup: centralizing return-type formatting reduces divergence.Using
get_return_type_str()inadd_builtin_function_stub()is a clear improvement and makes it easier to keep merged/unmerged stub paths consistent.warp/_src/builtins.py (7)
426-437: Quaternionisfinite/isnan/isinfnow float-only — looks consistent with the deprecation messaging.
Switching these overloads toquaternion(dtype=Float)prevents “integer quaternion” ambiguity while scalar/vector/matrix paths can continue the deprecation warning behavior.Also applies to: 475-486, 524-535
734-747:length_sq(quaternion)return-type inference matches the new float-only quaternion contract.
Usingfloat_sametypes_value_funchere is a good consistency improvement vs the vectorScalarvariant.
6925-6935: Hidereversed(range)from stubs/docs — aligns withrange/iter_nexttreatment.
8827-8854: Bool-specificextract()overloads are a solid fix for “bool not part of Scalar”.
Nice to see this handled explicitly for vector/matrix, and kept hidden since it’s an implementation detail.Also applies to: 8918-8936
9691-9733: Boolexpect_eq/expect_neqoverloads are consistent with the Scalar/bool split.
9124-9247: No action needed: Quaternion/Transformation dtype migration is complete.The codebase contains zero instances of non-float quaternion or transformation usage. All type definitions (quath, quatf, quatd, transformh, transformf, transformd) are float-only, and default value functions return
Float. No int/bool dtypes are used, and dispatch implementations (quaternion_dispatch_func, transformation_dispatch_func) are properly defined and consistent with the runtime code.
8978-8988: The boolindex/indexrefoverloads are properly supported by the backend. Tests intest_bool.pyconfirm that bool vector and matrix element access works correctly, including reading from bool_selector_vec[0] and bool_selector_mat[0,0]. The C++vec_t<Length, Type>template handles bool uniformly as any other scalar type, andReference(bool)correctly generates tobool*in compiled code with proper namespace handling.Likely an incorrect or invalid review comment.
warp/__init__.pyi (7)
1781-1789: LGTM!The kernel-scope
zerosoverloads correctly returnArray[Scalar]to support creating arrays of any scalar dtype.
2004-2011: LGTM!The Quaternion type parameter changes from
ScalartoFloatcorrectly align with theQuaternion(Generic[Float])definition intypes.py, resolving type-checker warnings about overlapping overloads.Also applies to: 2040-2047, 2076-2083, 2143-2146
4571-4587: LGTM!The consolidated
tid()signature with a union return type elegantly captures the unpacking-based semantics while avoiding overlapping overload issues. The comprehensive docstring clearly documents the behavior for each unpacking pattern. Based on retrieved learnings, the note that this function is kernel-only is correctly preserved.
2266-2266: LGTM!The explicit
-> Nonereturn type annotations for void functions improve type safety and Pyright compliance. This is best practice for stub files.Also applies to: 2287-2287, 2307-2307, 2325-2325, 2367-2367, 2433-2437, 2540-2550, 4559-4567
5699-5699: LGTM!The Quaternion and Transformation operator overloads correctly use
Floatas the type parameter, consistent with their generic definitions. The use ofScalarfor scalar operands inmulanddivis appropriate since multiplying/dividing a quaternion by any numeric type (int or float) should be valid.Also applies to: 5709-5709, 5734-5734, 5739-5739, 5869-5881, 5909-5921, 5969-5975, 5993-5993, 6013-6013
6301-6304: LGTM!Consistent with the other Quaternion type parameter updates.
2897-2897: LGTM!The
-> Nonereturn type annotations for tile operations are appropriate for in-place and void functions.Also applies to: 2911-2911, 2917-2917, 3095-3095, 3369-3369, 6087-6088, 6132-6132, 6146-6146, 6179-6179, 6213-6213, 6245-6245, 6279-6279
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
warp/_src/builtins.py (2)
7628-7735: Add regression test fortid()kernel-only restriction andblock_dim()allowed in@wp.func.The compiler already enforces kernel-only restrictions for
tid()viacheck_tid_in_func_error()in codegen.py, andblock_dim()is properly exported (defaultexport=True). However, add a test case to ensure:
@wp.funccallingtid()raisesWarpCodegenError@wp.funccallingblock_dim()succeeds
9124-9258: Scalar-multiply/divide overloads use flexibleScalarinput type but enforce strict type matching.The quaternion and transformation scalar-multiply/divide operations accept
Scalarin their input_types (e.g.,"b": Scalar), but thescalar_mul_create_value_funcconstraint requires the scalar type to exactly match the compound type's dtype. Forquaternion(dtype=Float), this means the scalar must beFloat, notint. Users writingquat * 2will hit a runtime error "Object and coefficient must have the same scalar type when multiplying by scalar" if Warp infers the literal2asint. Consider either constraining scalar factors toFloatexplicitly (matching the compound type's actual requirement) or documenting that numeric literals must be float-typed.
🤖 Fix all issues with AI agents
In @warp/_src/context.py:
- Around line 8657-8665: Narrow the broad except in get_return_type_str:
explicitly catch TypeError when calling f.value_func(None, None) and silently
fall back to f.value_type, and add a separate except Exception as e branch that
logs the unexpected exception when verbose mode is enabled (using the project's
existing logging/verbose facility) before falling back to f.value_type; keep the
final return as type_str(return_type) and only suppress the well-known TypeError
case.
🧹 Nitpick comments (1)
warp/_src/context.py (1)
8920-8942: Overload merging only triggers when all overloads share inputs—consider grouping by signature.As written, you merge only if every non-hidden overload has the same
input_types. If a function has mixed overload groups (some identical inputs, some not), you’ll miss the merge opportunity that the helper name/PR intent suggests.Sketch of a grouping approach
- if len(non_hidden_overloads) > 1: - first = non_hidden_overloads[0] - first_inputs = tuple(sorted(first.input_types.items())) - all_same_inputs = all( - tuple(sorted(f.input_types.items())) == first_inputs for f in non_hidden_overloads - ) - - if all_same_inputs: - add_merged_builtin_function_stub(non_hidden_overloads) - continue + if len(non_hidden_overloads) > 1: + groups = {} + for f in non_hidden_overloads: + key = tuple(sorted(f.input_types.items())) + groups.setdefault(key, []).append(f) + if any(len(v) > 1 for v in groups.values()): + for v in groups.values(): + if len(v) > 1: + add_merged_builtin_function_stub(v) + else: + add_builtin_function_stub(v[0], use_overload=False) + continue
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
.github/workflows/ci.yml.gitlab-ci.ymldocs/_templates/builtins.rstdocs/language_reference/builtins.rstwarp/__init__.pyiwarp/_src/builtins.pywarp/_src/context.pywarp/_src/types.py
💤 Files with no reviewable changes (2)
- .github/workflows/ci.yml
- .gitlab-ci.yml
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1167
File: warp/tests/test_static.py:776-781
Timestamp: 2026-01-13T06:46:08.692Z
Learning: In the NVIDIA/warp repository, star imports like `from warp.tests.unittest_utils import *` in test files are acceptable per the project's Ruff configuration, and F405 warnings should not be flagged if pre-commit checks pass.
📚 Learning: 2026-01-13T17:29:07.264Z
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1171
File: warp/_src/builtins.py:7726-7735
Timestamp: 2026-01-13T17:29:07.264Z
Learning: In warp/_src/builtins.py (NVIDIA/warp), enforce that block_dim() may be called from user-defined Warp functions, while tid() is kernel-only and must not be called from Warp function bodies. Ensure the builtins registration and related usage enforce this distinction, and add tests to verify allowed vs disallowed calls in user-defined Warp functions.
Applied to files:
warp/_src/builtins.py
📚 Learning: 2025-09-28T18:45:45.955Z
Learnt from: StafaH
Repo: NVIDIA/warp PR: 925
File: warp/native/bvh.h:359-369
Timestamp: 2025-09-28T18:45:45.955Z
Learning: StafaH prefers to defer the BVH shared stack stride issue (hardcoded WP_BVH_BLOCK_DIM vs runtime blockDim.x) for a future update rather than implementing the dynamic shared memory solution now.
Applied to files:
warp/_src/builtins.py
📚 Learning: 2026-01-13T17:29:07.264Z
Learnt from: shi-eric
Repo: NVIDIA/warp PR: 1171
File: warp/_src/builtins.py:7726-7735
Timestamp: 2026-01-13T17:29:07.264Z
Learning: In NVIDIA/warp (PR #1171), block_dim() may be called from user-defined Warp functions, while tid() may not; tid() is kernel-only. File context: warp/_src/builtins.py builtins registration.
Applied to files:
warp/__init__.pyi
🧬 Code graph analysis (3)
warp/_src/types.py (1)
warp/__init__.pyi (6)
add(5689-5691)add(5694-5696)add(5699-5701)add(5704-5706)add(5709-5711)add(5714-5716)
warp/_src/builtins.py (2)
warp/_src/types.py (4)
quaternion(1222-1235)dtype(4972-4978)vector(527-736)matrix(740-1160)warp/__init__.pyi (9)
quaternion(2332-2336)quaternion(2339-2341)quaternion(2344-2346)quaternion(2349-2351)vector(2224-2226)length(2129-2131)length(2134-2136)matrix(2229-2240)matrix(2243-2245)
warp/__init__.pyi (3)
warp/_src/types.py (3)
Quaternion(262-263)Vector(254-255)Transformation(266-267)warp/native/array.h (1)
len(2218-2218)warp/native/mat.h (1)
len(5516-5519)
🪛 Ruff (0.14.11)
warp/_src/context.py
8663-8664: try-except-pass detected, consider logging the exception
(S110)
8663-8663: Do not catch blind exception: Exception
(BLE001)
warp/_src/builtins.py
428-428: quaternion may be undefined, or defined from star imports
(F405)
428-428: Float may be undefined, or defined from star imports
(F405)
477-477: quaternion may be undefined, or defined from star imports
(F405)
477-477: Float may be undefined, or defined from star imports
(F405)
526-526: quaternion may be undefined, or defined from star imports
(F405)
526-526: Float may be undefined, or defined from star imports
(F405)
743-743: quaternion may be undefined, or defined from star imports
(F405)
743-743: Float may be undefined, or defined from star imports
(F405)
8830-8830: vector may be undefined, or defined from star imports
(F405)
8839-8839: quaternion may be undefined, or defined from star imports
(F405)
8839-8839: Float may be undefined, or defined from star imports
(F405)
8848-8848: transformation may be undefined, or defined from star imports
(F405)
8848-8848: Float may be undefined, or defined from star imports
(F405)
8921-8921: matrix may be undefined, or defined from star imports
(F405)
8930-8930: matrix may be undefined, or defined from star imports
(F405)
8981-8981: vector may be undefined, or defined from star imports
(F405)
9025-9025: vector may be undefined, or defined from star imports
(F405)
9047-9047: matrix may be undefined, or defined from star imports
(F405)
9127-9127: quaternion may be undefined, or defined from star imports
(F405)
9127-9127: Float may be undefined, or defined from star imports
(F405)
9137-9137: transformation may be undefined, or defined from star imports
(F405)
9137-9137: Float may be undefined, or defined from star imports
(F405)
9165-9165: quaternion may be undefined, or defined from star imports
(F405)
9165-9165: Float may be undefined, or defined from star imports
(F405)
9176-9176: transformation may be undefined, or defined from star imports
(F405)
9176-9176: Float may be undefined, or defined from star imports
(F405)
9198-9198: quaternion may be undefined, or defined from star imports
(F405)
9198-9198: Float may be undefined, or defined from star imports
(F405)
9241-9241: quaternion may be undefined, or defined from star imports
(F405)
9241-9241: Float may be undefined, or defined from star imports
(F405)
9694-9694: vector may be undefined, or defined from star imports
(F405)
9694-9694: vector may be undefined, or defined from star imports
(F405)
9704-9704: vector may be undefined, or defined from star imports
(F405)
9704-9704: vector may be undefined, or defined from star imports
(F405)
9715-9715: matrix may be undefined, or defined from star imports
(F405)
9715-9715: matrix may be undefined, or defined from star imports
(F405)
9725-9725: matrix may be undefined, or defined from star imports
(F405)
9725-9725: matrix may be undefined, or defined from star imports
(F405)
9896-9896: quaternion may be undefined, or defined from star imports
(F405)
9896-9896: Float may be undefined, or defined from star imports
(F405)
9896-9896: quaternion may be undefined, or defined from star imports
(F405)
9896-9896: Float may be undefined, or defined from star imports
(F405)
9897-9897: quaternion may be undefined, or defined from star imports
(F405)
9897-9897: Float may be undefined, or defined from star imports
(F405)
9911-9911: transformation may be undefined, or defined from star imports
(F405)
9911-9911: Float may be undefined, or defined from star imports
(F405)
9911-9911: transformation may be undefined, or defined from star imports
(F405)
9911-9911: Float may be undefined, or defined from star imports
(F405)
9912-9912: transformation may be undefined, or defined from star imports
(F405)
9912-9912: Float may be undefined, or defined from star imports
(F405)
9938-9938: quaternion may be undefined, or defined from star imports
(F405)
9938-9938: Float may be undefined, or defined from star imports
(F405)
9938-9938: quaternion may be undefined, or defined from star imports
(F405)
9938-9938: Float may be undefined, or defined from star imports
(F405)
9939-9939: quaternion may be undefined, or defined from star imports
(F405)
9939-9939: Float may be undefined, or defined from star imports
(F405)
9945-9945: transformation may be undefined, or defined from star imports
(F405)
9945-9945: Float may be undefined, or defined from star imports
(F405)
9945-9945: transformation may be undefined, or defined from star imports
(F405)
9945-9945: Float may be undefined, or defined from star imports
(F405)
9946-9946: transformation may be undefined, or defined from star imports
(F405)
9946-9946: Float may be undefined, or defined from star imports
(F405)
10141-10141: quaternion may be undefined, or defined from star imports
(F405)
10141-10141: Float may be undefined, or defined from star imports
(F405)
10141-10141: Scalar may be undefined, or defined from star imports
(F405)
10142-10142: quaternion may be undefined, or defined from star imports
(F405)
10142-10142: Float may be undefined, or defined from star imports
(F405)
10148-10148: Scalar may be undefined, or defined from star imports
(F405)
10148-10148: quaternion may be undefined, or defined from star imports
(F405)
10148-10148: Float may be undefined, or defined from star imports
(F405)
10149-10149: quaternion may be undefined, or defined from star imports
(F405)
10149-10149: Float may be undefined, or defined from star imports
(F405)
10155-10155: quaternion may be undefined, or defined from star imports
(F405)
10155-10155: Float may be undefined, or defined from star imports
(F405)
10155-10155: quaternion may be undefined, or defined from star imports
(F405)
10155-10155: Float may be undefined, or defined from star imports
(F405)
10156-10156: quaternion may be undefined, or defined from star imports
(F405)
10156-10156: Float may be undefined, or defined from star imports
(F405)
10269-10269: transformation may be undefined, or defined from star imports
(F405)
10269-10269: Float may be undefined, or defined from star imports
(F405)
10269-10269: transformation may be undefined, or defined from star imports
(F405)
10269-10269: Float may be undefined, or defined from star imports
(F405)
10270-10270: transformation may be undefined, or defined from star imports
(F405)
10270-10270: Float may be undefined, or defined from star imports
(F405)
10276-10276: Scalar may be undefined, or defined from star imports
(F405)
10276-10276: transformation may be undefined, or defined from star imports
(F405)
10276-10276: Float may be undefined, or defined from star imports
(F405)
10277-10277: transformation may be undefined, or defined from star imports
(F405)
10277-10277: Float may be undefined, or defined from star imports
(F405)
10283-10283: transformation may be undefined, or defined from star imports
(F405)
10283-10283: Float may be undefined, or defined from star imports
(F405)
10283-10283: Scalar may be undefined, or defined from star imports
(F405)
10284-10284: transformation may be undefined, or defined from star imports
(F405)
10284-10284: Float may be undefined, or defined from star imports
(F405)
10344-10344: quaternion may be undefined, or defined from star imports
(F405)
10344-10344: Float may be undefined, or defined from star imports
(F405)
10344-10344: Scalar may be undefined, or defined from star imports
(F405)
10345-10345: quaternion may be undefined, or defined from star imports
(F405)
10345-10345: Float may be undefined, or defined from star imports
(F405)
10351-10351: Scalar may be undefined, or defined from star imports
(F405)
10351-10351: quaternion may be undefined, or defined from star imports
(F405)
10351-10351: Float may be undefined, or defined from star imports
(F405)
10352-10352: quaternion may be undefined, or defined from star imports
(F405)
10352-10352: Float may be undefined, or defined from star imports
(F405)
10376-10376: quaternion may be undefined, or defined from star imports
(F405)
10376-10376: Float may be undefined, or defined from star imports
(F405)
10377-10377: quaternion may be undefined, or defined from star imports
(F405)
10377-10377: Float may be undefined, or defined from star imports
(F405)
10398-10398: quaternion may be undefined, or defined from star imports
(F405)
10398-10398: Float may be undefined, or defined from star imports
(F405)
10399-10399: quaternion may be undefined, or defined from star imports
(F405)
10399-10399: Float may be undefined, or defined from star imports
(F405)
11871-11871: quaternion may be undefined, or defined from star imports
(F405)
11871-11871: Float may be undefined, or defined from star imports
(F405)
⏰ 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). (3)
- GitHub Check: ci / test-warp (ubuntu-24.04, ubuntu-x86_64)
- GitHub Check: ci / test-warp (windows-2025, windows)
- GitHub Check: ci / test-warp-gpu
🔇 Additional comments (28)
docs/_templates/builtins.rst (1)
20-20: LGTM! Docstring indentation fix improves RST rendering.The
indent(3, first=True)filter ensures multi-line docstrings render with consistent margins in the generated RST documentation.docs/language_reference/builtins.rst (1)
319-349: LGTM! Utility section relocation improves documentation organization.The Utility section is now appropriately positioned, and the inclusion of the newly exposed
block_dim()builtin aligns with the PR objectives.warp/_src/context.py (2)
8667-8681: Centralizing return-type formatting is a good cleanup.Using
get_return_type_str()makesadd_builtin_function_stub()more consistent, and emitting-> None(instead of omitting a return annotation) is generally better for type checkers.
8682-8714: Empty-list guard is unnecessary;.pyistub files don't require Python version syntax compatibility.The function is only called when
len(non_hidden_overloads) > 1(line 8923), so it never receives empty lists. The|union syntax in.pyistub files is valid regardless of Python version—type checkers (mypy, pyright, etc.) parse stubs and support modern syntax independently of runtime Python version.Likely an incorrect or invalid review comment.
warp/_src/types.py (4)
63-126: LGTM - Well-structured scalar base class.The operator overloads correctly return
NotImplementedfor array operands, allowing proper delegation to array's reflected operators. The runtime references tois_array()andwarp.*functions are safe since they're resolved at method invocation time.
147-168: LGTM - Intentional separation of bool from scalar_base.The
boolclass not inheriting fromscalar_baseis consistent with the PR objective to excludeboolfrom theScalarTypeVar. This ensuresboolis treated as a distinct type in the type system while still being usable in boolean contexts.
225-251: LGTM - Scalar TypeVar correctly excludes bool.The type hierarchy is well-organized:
scalar_typesexcludesbool, aligning with theScalarTypeVar definitionscalar_and_bool_typesis retained for contexts whereboolshould be included (e.g.,value_typesat line 2148)- The documentation comment at lines 231-233 is a good practice for keeping TypeVars synchronized with the tuples
2251-2254: LGTM - Runtime Scalar matching now aligns with static TypeVar definition.This change resolves the previously identified mismatch where static typing permitted
boolas aScalarbut runtime matching did not accept it. Now both are consistent:Scalarrepresents numeric types only (int_types+float_types), excludingbool.The impact of this change is mitigated by the explicit
boolvector/matrix overloads being added inbuiltins.py(lines 9691-9727) forexpect_eqandexpect_neqfunctions, as part of this PR.warp/_src/builtins.py (4)
402-449: Quaternion float-only predicates / norms look consistent.Switching
isfinite/isnan/isinf/length_sqquaternion overloads toquaternion(dtype=Float)matches the “float-only” direction implied byspecial_float_dispatch_funcand avoids nonsensical integer-quaternion surfaces.Also applies to: 451-498, 500-547, 718-747
6925-6935: Hidingreversed(range_t)from stubs/docs is consistent with other hidden iterators.
11859-11877:len(quaternion)update toFloatmatches the rest of the quaternion typing shift.
8827-9054: Bool vector/matrix overloads are complete and consistent.The added bool overloads for
extract,index,indexref, andexpect_eq/expect_neqare comprehensive. Bool matrices correctly use onlyindexrefoverloads (notindex), which matches the pattern for Scalar matrices—neitherScalarnorboolmatrix types haveindexoverloads. This is consistent:indexis reserved for vectors (returning scalars), whileindexrefhandles reference returns for both vectors and matrices. All indexing paths are properly covered.warp/__init__.pyi (16)
1781-1789: LGTM!The kernel-scope
zerosoverloads correctly provide signatures for both tuple and scalar shape arguments, returningArray[Scalar]. The empty docstrings are consistent with other kernel builtin stubs in this file.
2004-2011: LGTM!The quaternion type parameter correction from
ScalartoFloatis consistent withclass Quaternion(Generic[Float])intypes.py. This ensures type checker accuracy for these math functions.Also applies to: 2040-2047, 2076-2083, 2143-2146
2263-2270: LGTM!The in-place variants of
svd3,svd2,qr3, andeig3correctly returnNonesince they write results to output parameters rather than returning them. This follows Python conventions and improves type checker accuracy.Also applies to: 2281-2291, 2303-2311, 2322-2329
2366-2369: LGTM!The in-place
quat_to_axis_angleoverload correctly returnsNonesince it writes results to theaxisandangleoutput parameters.
2433-2438: LGTM!The transform setter functions correctly return
Noneas they mutate the transform in-place rather than returning a new value.
2532-2551: LGTM!The
spatial_jacobianandspatial_massfunctions correctly returnNoneas they write results to output array parameters (J_outandM).
2896-2917: LGTM!The
tile_storeandtile_store_indexedfunctions correctly returnNoneas they are write operations to global memory arrays.
3095-3102: LGTM!The
tile_assignfunction correctly returnsNoneas it assigns values to the destination tile in-place.
3369-3400: LGTM!The
tile_sortfunction correctly returnsNoneas it sorts both tiles in-place, which is clearly documented in the docstring.
3559-3569: LGTM!The
printf,breakpointfunctions correctly returnNoneas they are side-effect-only operations (output and debugging).
3571-3587: LGTM!The
tid()return type annotationint | tuple[int, int] | tuple[int, int, int] | tuple[int, int, int, int]accurately reflects that the return type depends on the unpacking context used at the call site. The comprehensive docstring clearly explains this behavior. This is an appropriate approach since the return semantics depend on assignment unpacking rather than function arguments.
4299-4301: LGTM!The volume store functions (
volume_store,volume_store_f,volume_store_v,volume_store_i) consistently returnNoneas they are write operations that store values to voxels.Also applies to: 4324-4326, 4342-4344, 4357-4359
5658-5676: LGTM!The
expect_nearoverloads correctly returnNoneas they are assertion/test helper functions that print errors to stdout but don't return a meaningful value.
5698-5711: LGTM!The arithmetic operations (
add,sub,mul,div,pos,neg) andlenforQuaternionandTransformationtypes now consistently useFloatas the type parameter. This aligns with the type definitions intypes.pywhere bothQuaternionandTransformationare defined asGeneric[Float].Also applies to: 5733-5740, 5868-5921, 5968-5976, 5992-5994, 6012-6014, 6301-6303
6081-6158: LGTM!The
tile_matmulin-place variant (withoutparameter) correctly returnsNone, while the non-in-place variant returns a tile. Thetile_fftandtile_ifftfunctions correctly returnNoneas they operate on the input/output tile in-place. TheFloattype parameter is appropriate for these floating-point operations.
6179-6196: LGTM!The in-place variants (
tile_cholesky_inplace,tile_cholesky_solve_inplace,tile_lower_solve_inplace,tile_upper_solve_inplace) correctly returnNoneas they overwrite their input parameters rather than returning new tiles. The docstrings clearly document this behavior.Also applies to: 6213-6227, 6245-6261, 6279-6295
| def get_return_type_str(f): | ||
| """Get the return type string for a builtin function.""" | ||
| return_type = f.value_type | ||
| if f.value_func: | ||
| try: | ||
| return_type = f.value_func(None, None) | ||
| except Exception: | ||
| pass # Keep f.value_type as fallback | ||
| return type_str(return_type) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, check if the file exists and read the relevant section
wc -l warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 80
🏁 Script executed:
# Read the function in question
sed -n '8650,8720p' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 2694
🏁 Script executed:
# Search for value_func usage patterns to understand what exceptions might occur
rg -n 'value_func' warp/_src/context.py | head -30Repository: NVIDIA/warp
Length of output: 1476
🏁 Script executed:
# Check for verbose warning patterns in the codebase
rg -n 'warp.config.verbose|config\.verbose' warp/ | head -20Repository: NVIDIA/warp
Length of output: 1601
🏁 Script executed:
# Check for Python version requirements
rg -n 'pythonVersion|python_version|requires-python|tool\.pyright' . --type toml --type yaml --type json --type txt | head -20Repository: NVIDIA/warp
Length of output: 537
🏁 Script executed:
# Search for existing exception handling patterns in export_stubs context
rg -B 3 -A 3 'except.*Exception' warp/_src/context.py | head -40Repository: NVIDIA/warp
Length of output: 1585
🏁 Script executed:
# Look at value_func implementations to understand what exceptions they might raise
sed -n '77,90p' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 542
🏁 Script executed:
# Check the create_value_func and other value_func definitions
rg -B 5 -A 15 'def value_func\(' warp/_src/context.py | head -60Repository: NVIDIA/warp
Length of output: 1335
🏁 Script executed:
# Check where value_func is called with (None, None) to see if this is a documented pattern
rg -B 3 -A 3 'value_func\(None, None\)' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 564
🏁 Script executed:
# Check the type_str function to see if it handles exceptions or if it's resilient
rg -B 2 -A 10 'def type_str' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 362
🏁 Script executed:
# Check if there are any docstrings or comments about expected behavior for value_func with None args
rg -B 5 -A 5 'value_func.*None|None.*value_func' warp/_src/context.py | head -40Repository: NVIDIA/warp
Length of output: 1447
🏁 Script executed:
# Check the context around line 8287 to see the similar exception handling pattern
sed -n '8280,8295p' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 613
🏁 Script executed:
# Verify how value_func is called in actual code execution vs stub generation
rg -B 5 -A 5 'value_func\(func_args|value_func\(concrete_arg' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 1144
🏁 Script executed:
# Check if there are any known error types that value_func can raise
rg -B 10 -A 10 'def value_func' warp/_src/context.py | grep -A 15 'def value_func'Repository: NVIDIA/warp
Length of output: 818
🏁 Script executed:
# Check pyproject.toml to see Pyright configuration for stub file generation
sed -n '212,230p' pyproject.tomlRepository: NVIDIA/warp
Length of output: 187
🏁 Script executed:
# Verify if generated stub files use PEP 604 syntax and what Python version they target
rg -n '\|' warp/ --type pyi | head -10Repository: NVIDIA/warp
Length of output: 82
🏁 Script executed:
# Check if there are any other patterns of value_func being called with None in the codebase
rg -n 'value_func\(None' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 185
🏁 Script executed:
# Look at the broader context of where stubs are generated to understand the scope
rg -n 'export_stubs|def export_stubs' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 103
🏁 Script executed:
# Check if warp._src.utils.warn is the appropriate function to use for warnings
rg -B 5 -A 10 'def warn' warp/_src/utils.py | head -30Repository: NVIDIA/warp
Length of output: 1117
🏁 Script executed:
# Verify the actual exceptions that might be raised from value_func implementations
rg -B 10 -A 20 'def value_func' warp/ | grep -E '(raise|except|TypeError|AttributeError)' -A 2 -B 2Repository: NVIDIA/warp
Length of output: 383
🏁 Script executed:
# Check line 8250 context where value_func is called with actual args to understand error patterns
sed -n '8240,8260p' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 731
🏁 Script executed:
# Check all value_func implementations to understand what exceptions they might actually raise
rg -B 3 -A 15 'def value_func' warp/_src/context.py | head -80Repository: NVIDIA/warp
Length of output: 1252
🏁 Script executed:
# Look at the actual exception being swallowed at line 8287 to see if there are patterns
sed -n '8275,8305p' warp/_src/context.pyRepository: NVIDIA/warp
Length of output: 903
🏁 Script executed:
# Check if verbose is used with stacklevel for warnings in similar contexts
rg -B 3 -A 3 'if.*verbose.*warn|warn.*stacklevel' warp/_src/context.py | head -30Repository: NVIDIA/warp
Length of output: 37
🏁 Script executed:
# Check if there are similar broad Exception catches elsewhere for context
rg -B 2 -A 2 'except Exception:' warp/_src/context.py | head -50Repository: NVIDIA/warp
Length of output: 1208
🏁 Script executed:
# Verify what the actual exception types might be from value_func with None args
python3 << 'EOF'
# Simulate what happens when calling value_func(None, None)
# For create_value_func pattern
def test_create_value_func():
def value_func(arg_types, arg_values):
hint_origin = getattr(type, "__origin__", None)
if hint_origin is not None and issubclass(hint_origin, tuple):
return type.__args__
return type
# Call with None, None
try:
result = value_func(None, None)
print("create_value_func with None args: Success")
except Exception as e:
print(f"create_value_func with None args: {type(e).__name__}: {e}")
# For simple value_func pattern
def test_simple_value_func():
value_type = int
def value_func(arg_types, arg_values):
return value_type
try:
result = value_func(None, None)
print(f"simple value_func with None args: Success, returned {result}")
except Exception as e:
print(f"simple value_func with None args: {type(e).__name__}: {e}")
test_create_value_func()
test_simple_value_func()
EOFRepository: NVIDIA/warp
Length of output: 141
🏁 Script executed:
# Check if the issue at line 8287 is also addressed or if it's a separate known issue
git log --oneline -20 -- warp/_src/context.py | head -20Repository: NVIDIA/warp
Length of output: 119
Catch TypeError explicitly; log unexpected exceptions under verbose mode.
The broad Exception catch can obscure bugs in custom value_func implementations. Since value_func is a user-provided callback, implementations may raise exceptions beyond the typical TypeError from None-argument incompatibility. While the current fallback to f.value_type is safe, narrowing the exception handler and logging unexpected errors improves debuggability.
Suggested change
def get_return_type_str(f):
"""Get the return type string for a builtin function."""
return_type = f.value_type
if f.value_func:
try:
return_type = f.value_func(None, None)
- except Exception:
- pass # Keep f.value_type as fallback
+ except TypeError:
+ # Common case: value_func requires non-None args
+ pass
+ except Exception as e:
+ if warp.config.verbose:
+ warp._src.utils.warn(
+ f"Stub generation: failed to infer return type for '{getattr(f, 'key', f)}': {e}",
+ stacklevel=3,
+ )
return type_str(return_type)🧰 Tools
🪛 Ruff (0.14.11)
8663-8664: try-except-pass detected, consider logging the exception
(S110)
8663-8663: Do not catch blind exception: Exception
(BLE001)
🤖 Prompt for AI Agents
In @warp/_src/context.py around lines 8657 - 8665, Narrow the broad except in
get_return_type_str: explicitly catch TypeError when calling f.value_func(None,
None) and silently fall back to f.value_type, and add a separate except
Exception as e branch that logs the unexpected exception when verbose mode is
enabled (using the project's existing logging/verbose facility) before falling
back to f.value_type; keep the final return as type_str(return_type) and only
suppress the well-known TypeError case.
Description
1. Hide
reversedbuilt-in from stubsMark
reversedas hidden (similar torangeanditer_next) to remove it from generated stubs and documentation.2. Fix RST template docstring indentation
Apply Jinja's
indentfilter withfirst=Trueso multi-line docstrings render with consistent margins in the documentation.3. Merge overlapping
wp.tid()overloadsResolve type checker warnings about overlapping function signatures by:
wp.tid()docstrings across all overloadsadd_merged_builtin_function_stub()to auto-detect and merge overloads with identical input types into a single stub with union return typeScalar→Float) forisfinite/isnan/isinf/length_sqtypes.pyfor earlier availability4. Enable Pyright stubs job
Remove
allow_failurefrom the Pyright stubs validation job in both GitHub Actions and GitLab CI.5. Fix
ScalarTypeVar consistency and add bool vector/matrix overloadsAddress CodeRabbit feedback about misaligned
Scalargenerics:boolandbuiltins.boolfrom theScalarTypeVar constraints—Scalarnow represents "numeric scalar" types only (int/float variants)scalars_equal_generic()intypes_match()to usescalar_typesinstead ofscalar_and_bool_types, aligning withtype_matches_template()behaviorStopIterationcrashes invalue_funchelpers likescalar_mul_create_value_func()that search onlyscalar_typesSince
boolvectors and matrices are a valid feature (distinct from numeric vectors), add explicit overloads for:expect_eq/expect_neqforvector(dtype=bool)andmatrix(dtype=bool)extractforvector(dtype=bool)andmatrix(dtype=bool)(1D and 2D indexing)index/indexrefforvector(dtype=bool)andmatrix(dtype=bool)6. Harden stub generation against
value_funcerrorsWrap
f.value_func(None, None)calls inget_return_type_str()with try-except to gracefully fall back tof.value_typewhen the function doesn't support None arguments. This prevents stub generation crashes and ensures all return types (includingNone) are correctly emitted in stubs.Files Changed
reversedbuiltins.py,__init__.pyi,builtins.rstdocs/_templates/builtins.rstcontext.py,builtins.py,types.py,__init__.pyi.github/workflows/ci.yml,.gitlab-ci.ymltypes.py,builtins.pyBefore your PR is "Ready for review"
__init__.pyi,docs/api_reference/,docs/language_reference/)pre-commit run -aSummary by CodeRabbit
New Features
Improvements
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.