Skip to content

[doc-only] docs(cuda.core): use PEP 604 unions in docstrings - #2601

Open
aryanputta wants to merge 1 commit into
NVIDIA:mainfrom
aryanputta:maint/docstring-pep604-types
Open

[doc-only] docs(cuda.core): use PEP 604 unions in docstrings#2601
aryanputta wants to merge 1 commit into
NVIDIA:mainfrom
aryanputta:maint/docstring-pep604-types

Conversation

@aryanputta

@aryanputta aryanputta commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #2597.

What

Replaces Union[...] and Optional[...] in cuda_core docstrings with the PEP 604 | form. 33 parameter lines across _launch_config.pyx, _module.pyx, and _program.pyx.

This matches the spelling the rest of the package already uses, for example stream : Stream | None, optional in _memoryview.pyx and preferred_location : int | None, optional in _memory/_managed_memory_resource.pyx.

In _module.pyx it also brings the max_potential_block_size docstring back in line with its own signature, which already reads dynamic_shared_memory_needed: int | driver.CUoccupancyB2DSize.

Scope

Docstrings only. Every edit is a type-descriptor substitution; the parameter names, the , optional suffixes, and the surrounding prose are untouched.

The .pyi half of the diff is the stubgen-pyx output for the three edited .pyx files, produced by running the repo's own stubgen-pyx-cuda-core hook rather than by hand. Regenerating all 45 stubs touched only these three, so the checked-in stubs were already in sync.

Two code-level spellings are deliberately left alone:

  • LinkerHandleT in _linker.pyx is a runtime value, not an annotation. _program.pyx builds ProgramHandleT = nvrtc.nvrtcProgram | int | LinkerHandleT from it, and PEP 604 | applied to the forward-reference strings it holds raises TypeError. It has to stay a typing.Union object.
  • The union_type literal in _process_define_macro is runtime error-message text rather than a docstring.

Sequence[...] and Iterable[...] elsewhere in cuda_core are collections.abc generics and are already current, so they are untouched.

No release note, since nothing user-visible changes at runtime.

Verification

pre-commit run --files over the six changed files passes, including mypy-cuda-core, cython-lint, and the stub generation seal.

Since these are docstrings that Sphinx renders, I also ran the 21 affected Parameters/Attributes docstrings through sphinx.ext.napoleon.NumpyDocstring plus a docutils parse, comparing the parent commit against this one: no new docutils messages are introduced. Each rewritten pipe carries a space on both sides, so none of them forms an RST substitution reference.

After this change the only remaining Union[/Optional[ occurrences in cuda_core are the two code-level ones listed above.

Docstrings across cuda_core still spelled parameter types with the
pre-3.10 typing generics. Replace Union[...] and Optional[...] with the
| form the rest of the package already uses, e.g. `stream : Stream |
None, optional` in _memoryview.pyx.

Docstrings only, so the .pyi changes are the stubgen-pyx output for the
edited .pyx files and no runtime behavior moves. In _module.pyx this also
realigns the max_potential_block_size docstring with its signature, which
already reads int | driver.CUoccupancyB2DSize.

Two code-level spellings stay as they are:

- LinkerHandleT in _linker.pyx is a runtime value, not an annotation.
  _program.pyx builds ProgramHandleT from it with `nvrtc.nvrtcProgram |
  int | LinkerHandleT`, and PEP 604 `|` on the forward-reference strings
  it holds raises TypeError.
- The union_type literal in _process_define_macro is error-message text
  rather than a docstring.

Sequence[...] and Iterable[...] elsewhere in cuda_core are
collections.abc generics and are unaffected.

Signed-off-by: Aryan <aryansputta@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT: Don't use old type descriptors in docstrings

1 participant