Skip to content

Commit 8c70110

Browse files
committed
fixup! feat(core.utils): use collections.abc.Sequence to match _prepare_nvrtc_options_impl
1 parent c8c590e commit 8c70110

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import abc
21+
import collections.abc
2122
import contextlib
2223
import hashlib
2324
import os
@@ -332,9 +333,15 @@ def _option_is_set(options: ProgramOptions, name: str) -> bool:
332333
if name in _BOOLEAN_OPTION_FIELDS:
333334
return bool(value)
334335
if name in _STR_OR_SEQUENCE_OPTION_FIELDS:
336+
# Mirror ``_prepare_nvrtc_options_impl``: it checks ``isinstance(v, str)``
337+
# first, then ``is_sequence(v)`` (which is ``isinstance(v, Sequence)``).
338+
# We therefore accept any ``collections.abc.Sequence`` (range, deque,
339+
# user subclass, etc.), not just list/tuple.
335340
if isinstance(value, str):
336341
return True
337-
return isinstance(value, (list, tuple)) and len(value) > 0
342+
if isinstance(value, collections.abc.Sequence):
343+
return len(value) > 0
344+
return False
338345
return True
339346

340347

cuda_core/tests/test_program_cache.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ def _flaky_replace(src, dst):
431431
pytest.param({"pre_include": "stdint.h"}, id="pre_include"),
432432
pytest.param({"pch": True}, id="pch"),
433433
pytest.param({"pch_dir": "pch-cache"}, id="pch_dir"),
434+
# Non-list/tuple Sequence: the compiler iterates it via ``is_sequence``
435+
# (``isinstance(v, Sequence)``), so the guard must too.
436+
pytest.param({"include_path": range(1)}, id="include_path_nonempty_range"),
434437
# Empty-string path-like options -- NVRTC still emits a flag
435438
# (``--use-pch=``, ``--pch-dir=``, ``--pre-include=``) so the guard
436439
# must fire for them too.
@@ -466,6 +469,10 @@ def test_make_program_cache_key_rejects_external_content_without_extra_digest(op
466469
# is silently ignored at compile time and must not trip the guard.
467470
pytest.param({"include_path": False}, id="include_path_false"),
468471
pytest.param({"pre_include": False}, id="pre_include_false"),
472+
# Empty non-list/tuple Sequence: ``_prepare_nvrtc_options_impl`` uses
473+
# ``is_sequence`` (i.e. ``isinstance(v, Sequence)``); a zero-length
474+
# sequence produces no emission regardless of type.
475+
pytest.param({"include_path": range(0)}, id="include_path_empty_range"),
469476
],
470477
)
471478
def test_make_program_cache_key_accepts_empty_external_content(option_kw):

0 commit comments

Comments
 (0)