Skip to content

Preserve Python annotation normalization errors on the Numba _sig path #773

Description

@coderabbitai

Summary

annotations_to_strings in plugins/python/src/modulewrap.cpp handles Numba CFunc annotations through the callable's _sig attribute. In that branch, annotation_as_text(ret) and annotation_as_text(item) may return an empty string after a Python API failure, but the current flow appends the empty result and sets conversion_ok = true without checking whether a Python exception is pending.

Required change

Update the _sig annotation-processing path in annotations_to_strings to detect annotation-normalization failures before treating the signature as successfully converted:

  • Check the result of normalizing the return annotation and every argument annotation.
  • Check PyErr_Occurred() as needed to distinguish a valid empty annotation string from a Python-error result.
  • On normalization failure, return false without populating invalid signature types or setting conversion_ok = true.
  • Preserve the existing successful behavior for valid annotations, including intentionally empty annotation text when no Python error is pending.

Rationale

Continuing registration with invalid/empty signature types while a Python exception remains pending can cause misleading downstream validation behavior and obscures the original normalization failure.

Affected area

  • plugins/python/src/modulewrap.cpp
  • annotations_to_strings
  • Numba CFunc _sig annotation handling

Acceptance criteria

  • A failure in annotation_as_text for _sig.return_type or any _sig.args entry causes annotations_to_strings to return false.
  • The originating Python exception remains available to the Python caller.
  • Invalid/partial signature types are not added to the output vectors on failure.
  • Valid _sig annotations continue to register unchanged.

Backlinks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions