Skip to content

[BUG]: ProgramOptions(name=None) raises AttributeError despite the str | None annotation #2516

Description

@aryanputta

Is this a duplicate?

Type of Bug

Runtime Error

Component

cuda.core

Describe the bug

ProgramOptions.name is annotated as accepting None:

name: str | None = "default_program"

but __post_init__ calls .encode() on it unconditionally:

def __post_init__(self) -> None:
    self._name = self.name.encode()

So ProgramOptions(name=None) raises AttributeError: 'NoneType' object has no attribute 'encode'. The annotation and the docstring (name : str, optional) both read as permission to pass None.

This is the only field in __post_init__ whose None case is not handled. arch normalizes two lines below:

if self.arch is None:
    self.arch = f"sm_{Device().arch}"

The failure happens at the .encode() call, before Device() is consulted, so it reproduces without a CUDA context.

How to Reproduce

from cuda.core import ProgramOptions

ProgramOptions(name=None)

Expected behavior

Either None is accepted and normalized to the documented default "default_program", matching how arch is handled in the same method, or the annotation is narrowed to str so the type no longer advertises a value that cannot be passed.

I have a patch for the first option and will open a PR shortly.

Additional context

The None path has no test coverage today: every ProgramOptions(name=...) in cuda_core/tests/test_program.py passes a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNeeds the team's attention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions