Skip to content

Consolidate enum casters into reusable macro#514

Merged
evertlammerts merged 1 commit into
duckdb:mainfrom
evertlammerts:prototype/caster-none-prep
Jun 26, 2026
Merged

Consolidate enum casters into reusable macro#514
evertlammerts merged 1 commit into
duckdb:mainfrom
evertlammerts:prototype/caster-none-prep

Conversation

@evertlammerts

Copy link
Copy Markdown
Member

Shrink the nanobind-porting surface of the custom type casters (pybind11-side prep only; no nanobind introduced).

Enum caster consolidation:

  • Add conversions/enum_string_caster.hpp defining two reusable macros: DUCKDB_PY_ENUM_STRING_INT_CASTER(EnumType, FromStringFn, FromIntegerFn, Name) for the str+int+enum shape, and DUCKDB_PY_ENUM_STRING_CASTER(EnumType, FromStringFn, Name) for the str-only shape (CSV line terminator).
  • Reduce the 6 hand-written type_caster specializations (explain, render_mode, python_csv_line_terminator, python_udf_type, null_handling, exception_handling) to a single macro invocation each. Behavior is identical; the per-enum FromString/FromInteger free functions are unchanged. The eventual nanobind caster rewrite is now a one-place change.

None-nullability audit:

  • Add an in-code nanobind porting note to pyconnection_default.hpp.

Shrink the nanobind-porting surface of the custom type casters (pybind11-side
prep only; no nanobind introduced).

Enum caster consolidation:
- Add conversions/enum_string_caster.hpp defining two reusable macros:
  DUCKDB_PY_ENUM_STRING_INT_CASTER(EnumType, FromStringFn, FromIntegerFn, Name)
  for the str+int+enum shape, and DUCKDB_PY_ENUM_STRING_CASTER(EnumType,
  FromStringFn, Name) for the str-only shape (CSV line terminator).
- Reduce the 6 hand-written type_caster specializations (explain, render_mode,
  python_csv_line_terminator, python_udf_type, null_handling,
  exception_handling) to a single macro invocation each. Behavior is identical;
  the per-enum FromString/FromInteger free functions are unchanged. The eventual
  nanobind caster rewrite is now a one-place change.

None-nullability audit:
- Add an in-code nanobind porting note to pyconnection_default.hpp.
@evertlammerts evertlammerts merged commit 664d7e4 into duckdb:main Jun 26, 2026
28 of 30 checks passed
@evertlammerts evertlammerts deleted the prototype/caster-none-prep branch June 26, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant