welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder::rods::pybind11::rod< DocStyle > Struct Template Reference

The pybind11 rod: a stateless policy type satisfying welder::rod. More...

#include <welder/rods/python/pybind11/rod.hpp>

Classes

struct  enum_handle
 Owning handle for a py::native_enum<E>, plus the scope + name to reach the finalized enum object. More...

Public Types

using module_type = py::module_
 pybind11's module handle.
template<class T>
using construction_type
 The type welder constructs when binding T — its registered trampoline if one exists, else T — so an abstract base with a trampoline stays constructible from a Python subclass.
template<class T>
using class_handle_type
 The class / enum handles the per-class / per-enum hooks operate on — exactly what make_class / make_enum yield.
template<class E>
using enum_handle_type = enum_handle<E>

Static Public Member Functions

static consteval const char * special_method_name (std::meta::info op_fn)
 Map a member operator to its Python dunder (nullptr = not exposed).
template<class T, auto Bases, std::size_t... I>
static auto make_class (module_type &m, const char *name, const char *doc, std::index_sequence< I... > seq)
 Create the py::class_<T, Bases…> handle, weaving in a trampoline when T is a welded virtual type with a registered welder::rods::python::trampoline_for.
template<class T, auto Bases, std::size_t... I>
static auto make_nested_class (module_type &, auto &outer_cls, const char *name, const char *doc, std::index_sequence< I... > seq)
 Create the py::class_ for a nested member type T, registered under its enclosing type's class handle rather than the module — Python then sees it as module.Outer.Inner (and __qualname__ nests), exactly like a hand-written py::class_<Outer::Inner>(outer_cls, "Inner").
template<class T, auto Ctors, bool HasDefault, bool Aggregate>
static void add_constructors (auto &cls)
 Bind T's whole constructor set (a chained-def framework just loops it): the default constructor when HasDefault, a py::init<…> per member of Ctors, and the synthesized aggregate field constructor when Aggregate.
template<std::meta::info Mem, class Style = ::welder::naming::none>
static void add_field (auto &cls)
 Bind data member Mem as an attribute.
template<auto Fns, class Style = ::welder::naming::none>
static void add_method (auto &cls)
 Bind method overload group Fns (name from Fns[0]; pybind11 chains one .def per overload and dispatches at call time).
template<auto Fns, class Style = ::welder::naming::none>
static void add_static_method (auto &cls)
 Bind static-method overload group Fns.
template<auto Fns>
static void add_operator (auto &cls)
 Bind operator overload group Fns under its Python dunder (one operator + arity per group, so Fns[0] names the slot).
template<class E>
static enum_handle< E > make_enum (module_type &m, const char *name, const char *doc)
 Create the enum_handle for E (a non-null doc becomes its docstring).
template<class E>
static enum_handle< E > make_nested_enum (module_type &, auto &outer_cls, const char *name, const char *doc)
 Create the enum_handle for a nested member enum E, scoped to its enclosing type's class handle — Python sees module.Outer.Mode, and an unscoped* nested enum's export_values() lands its enumerators on the class (mirroring C++'s Outer::red).
template<std::meta::info Enum, class Style = ::welder::naming::none>
static void add_enumerator (auto &e)
 Add enumerator Enum to the enum handle.
template<class E>
static void finish_enum (auto &e)
 Finalize enum E: export an unscoped enum's values into the enclosing scope, then commit the enum to the module.
static py::dict open_module (module_type &)
 Open a per-module session: a dict accumulating live (mutable-variable) properties; _install_live_properties() applies them in one __class__ swap at close.
static void set_module_doc (module_type &m, const char *doc)
 Set the (sub)module docstring.
template<auto Fns, class Style = ::welder::naming::none>
static py::object add_function (module_type &m, const char *name=nullptr)
 Bind free-function overload group Fns as one module-level function (name from Fns[0]; one chained .def per overload).
template<std::meta::info Var, class Style = ::welder::naming::none>
static void add_variable (module_type &m, py::dict &live, const char *name_override=nullptr)
 Bind namespace variable Var as a module attribute.
static module_type add_submodule (module_type &m, const char *name)
 Create a submodule named name under m.
static void close_module (module_type &m, py::dict &live)
 Close the session: apply any accumulated live properties.

Static Public Attributes

static constexpr lang language {lang::py}
 welder::lang::py.
template<class T>
static constexpr bool has_native_caster = !_needs_registration<T>
 caster_oracle: T is convertible without welder registering a class for it iff pybind11 does not fall back to runtime class registration.

Static Protected Member Functions

static consteval py::return_value_policy _return_value_policy (::welder::rv_kind k)
 Map welder's neutral welder::rv_kind to pybind11's return_value_policy.
template<std::meta::info Fn, class Def, std::size_t... I, std::size_t... K>
static void _def_function (const char *name, Def def_into, std::index_sequence< I... >, std::index_sequence< K... >)
 Register the function/method reflected by Fn onto a pybind11 target.
template<std::meta::info Fn, class Def>
static void _def_function (const char *name, Def def_into)
 Convenience overload: derive the parameter and keep_alive index sequences from Fn.
template<std::meta::info Ctor, std::size_t... I>
static void _def_init (auto &cls, std::index_sequence< I... >)
 Register py::init<P0, P1, …>() for constructor Ctor.
template<class T, std::size_t... I>
static void _def_aggregate_init (auto &cls, std::index_sequence< I... >)
 Synthesize a field constructor for a baseless aggregate T.
static void _install_live_properties (py::module_ &m, py::dict props)
 Give module m live get/set semantics for the names in props.
template<class T, class Trampoline, auto Bases, std::size_t... I>
static auto _make_class (py::handle scope, const char *name, const char *doc, std::index_sequence< I... >)
 Construct py::class_<T, NativeBases...> from a reflected base-type array.
template<class T, auto Bases, std::size_t... I>
static auto _make_class_at (py::handle scope, const char *name, const char *doc, std::index_sequence< I... > seq)
 The trampoline-aware class factory over an arbitrary registration scope — the shared body of make_class (scope = the module) and make_nested_class (scope = the enclosing class handle).

Static Protected Attributes

template<class T>
static constexpr bool _needs_registration
 Whether pybind11 can only convert T via runtime class registration.

Detailed Description

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
struct welder::rods::pybind11::rod< DocStyle >

The pybind11 rod: a stateless policy type satisfying welder::rod.

Its public static members are the pybind11 emission primitives welder's driver calls; the driver supplies all the reflection-derived decisions. Each implements the correspondingly-named hook of the welder::rod contract (and welder::caster_oracle) — every one carries a @see back to it, where the shared parameter and return-value semantics are documented once rather than repeated on each backend's mirror. The protected members below are pybind11-specific implementation helpers (prefixed _), not part of the contract.

Template Parameters
DocStylethe docstring convention this rod folds function/parameter/ return docs into (a welder::doc_style). Defaults to welder::rods::python::google_style; pass welder::rods::python::numpy_style or welder::rods::python::sphinx_style to emit those dialects. Defaulted, so rod<> is the Google-style rod and code that wants a different dialect names rod<numpy_style>.

Definition at line 71 of file rod.hpp.

Member Typedef Documentation

◆ class_handle_type

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T>
using welder::rods::pybind11::rod< DocStyle >::class_handle_type
Initial value:
std::declval<module_type&>(), nullptr, nullptr, std::index_sequence<>{}))
static auto make_class(module_type &m, const char *name, const char *doc, std::index_sequence< I... > seq)
Create the nb::class_<T, Bases…> handle, weaving in a trampoline when T is a welded virtual type with...
Definition rod.hpp:371

The class / enum handles the per-class / per-enum hooks operate on — exactly what make_class / make_enum yield.

class_handle_type<T> tracks make_class itself (so it captures the woven-in trampoline for a virtual T); it is its return type for a base-less T — welded bases, chosen by the carriage's resolution* rather than by T, are appended by make_class and so cannot be a function of T alone. Named as associated types so the welder::rod concept can shape-check the per-handle hooks against them. (Co-located with enum_handle, its definition.)

Definition at line 557 of file rod.hpp.

◆ construction_type

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T>
using welder::rods::pybind11::rod< DocStyle >::construction_type
Initial value:
consteval std::meta::info construction_type_of()
The type welder constructs when binding T: its registered/annotated trampoline if one exists,...

The type welder constructs when binding T — its registered trampoline if one exists, else T — so an abstract base with a trampoline stays constructible from a Python subclass.

The driver reads this to decide default constructibility.

See also
welder::rods::python::construction_type_of

Definition at line 368 of file rod.hpp.

◆ enum_handle_type

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class E>
using welder::rods::pybind11::rod< DocStyle >::enum_handle_type = enum_handle<E>

Definition at line 559 of file rod.hpp.

◆ module_type

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
using welder::rods::pybind11::rod< DocStyle >::module_type = py::module_

pybind11's module handle.

Definition at line 73 of file rod.hpp.

Member Function Documentation

◆ _def_aggregate_init()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, std::size_t... I>
void welder::rods::pybind11::rod< DocStyle >::_def_aggregate_init ( auto & cls,
std::index_sequence< I... >  )
inlinestaticprotected

Synthesize a field constructor for a baseless aggregate T.

Emits py::init([](F0 f0, …) { return T{f0, …}; }, py::arg("f0"), …) so Python can build it from field values (T(f0, f1)) rather than only default-construct then assign.

Template Parameters
Tthe aggregate type.
Ithe field index pack.
Parameters
clsthe class handle.

Definition at line 229 of file rod.hpp.

References welder::detail::aggregate_fields().

Referenced by add_constructors().

◆ _def_function() [1/2]

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Fn, class Def>
void welder::rods::pybind11::rod< DocStyle >::_def_function ( const char * name,
Def def_into )
inlinestaticprotected

Convenience overload: derive the parameter and keep_alive index sequences from Fn.

Definition at line 194 of file rod.hpp.

References _def_function(), and welder::detail::keep_alive_pairs().

◆ _def_function() [2/2]

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Fn, class Def, std::size_t... I, std::size_t... K>
void welder::rods::pybind11::rod< DocStyle >::_def_function ( const char * name,
Def def_into,
std::index_sequence< I... > ,
std::index_sequence< K... >  )
inlinestaticprotected

Register the function/method reflected by Fn onto a pybind11 target.

The folded docstring is passed when non-empty, and py::arg(name)... when every parameter is named (so Python callers see real keyword arguments, not arg0/arg1). Two call policies ride along as trailing .def extras: the [[=welder::return_policy]] (mapped to return_value_policy, always passed — automatic is pybind11's default, so an unannotated call is unchanged) and each [[=welder::keep_alive]] (spliced as py::keep_alive<nurse, patient>()). A reference-category policy on a by-value return is rejected first (welder::validate_return_policy).

Template Parameters
Fna reflection of the function.
Defthe target-adapter callable type.
Ithe parameter index pack.
Kthe keep_alive-dependency index pack.
Parameters
namethe Python name.
def_intoadapts the target — cls.def, cls.def_static, or m.def.

Definition at line 163 of file rod.hpp.

References _return_value_policy(), welder::detail::all_params_named(), welder::doc(), welder::function_docstring(), welder::detail::keep_alive_pairs(), language, welder::none, welder::detail::param_names(), welder::return_policy_of(), and welder::validate_return_policy().

Referenced by _def_function(), add_function(), add_method(), add_operator(), and add_static_method().

◆ _def_init()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Ctor, std::size_t... I>
void welder::rods::pybind11::rod< DocStyle >::_def_init ( auto & cls,
std::index_sequence< I... >  )
inlinestaticprotected

Register py::init<P0, P1, …>() for constructor Ctor.

Names the parameters (py::arg) when all are named, otherwise positional.

Template Parameters
Ctora reflection of the constructor.
Ithe parameter index pack.
Parameters
clsthe class handle.

Definition at line 210 of file rod.hpp.

References welder::detail::all_params_named(), welder::detail::param_names(), and welder::detail::param_types().

Referenced by add_constructors().

◆ _install_live_properties()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
void welder::rods::pybind11::rod< DocStyle >::_install_live_properties ( py::module_ & m,
py::dict props )
inlinestaticprotected

Give module m live get/set semantics for the names in props.

Reassigns m's Python class to a fresh subclass of its current class carrying props (name → property). Python modules don't support properties directly, but a module's __class__ may be swapped for a ModuleType subclass. Used only when a (sub)module exposes a mutable variable.

Subclassing the module's current class — rather than ModuleType outright — means repeated installs onto the same handle accumulate: welding a standalone variable and then a whole namespace onto the same module each add a layer, and the earlier properties survive in the MRO instead of being clobbered.

Parameters
mthe module handle.
propsa dict of name → property.

Definition at line 252 of file rod.hpp.

Referenced by close_module().

◆ _make_class()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, class Trampoline, auto Bases, std::size_t... I>
auto welder::rods::pybind11::rod< DocStyle >::_make_class ( py::handle scope,
const char * name,
const char * doc,
std::index_sequence< I... >  )
inlinestaticprotected

Construct py::class_<T, NativeBases...> from a reflected base-type array.

A non-null doc becomes the class docstring (pybind11 treats a bare const char* extra as the doc); nullptr is branched out rather than passed, since pybind11 would strdup it.

Template Parameters
Tthe class type.
Basesthe static array of native base type reflections.
Ithe base index pack.
Parameters
scopethe registration scope — the module, or (for a nested type) the enclosing class handle; pybind11 accepts any handle.
namethe Python class name.
docthe class docstring, or nullptr.

Definition at line 282 of file rod.hpp.

References welder::doc().

Referenced by _make_class_at().

◆ _make_class_at()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, auto Bases, std::size_t... I>
auto welder::rods::pybind11::rod< DocStyle >::_make_class_at ( py::handle scope,
const char * name,
const char * doc,
std::index_sequence< I... > seq )
inlinestaticprotected

The trampoline-aware class factory over an arbitrary registration scope — the shared body of make_class (scope = the module) and make_nested_class (scope = the enclosing class handle).

A type carrying virtual methods is bound overridable — it must register a trampoline (so Python subclasses can override those virtuals) or opt out with [[=welder::rods::python::bind_flat]]. When a trampoline is present, its coverage of T's virtuals is checked at compile time.

See also
welder::rods::python::trampoline_for

Definition at line 307 of file rod.hpp.

References _make_class(), and welder::doc().

Referenced by make_class(), and make_nested_class().

◆ _return_value_policy()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
consteval py::return_value_policy welder::rods::pybind11::rod< DocStyle >::_return_value_policy ( ::welder::rv_kind k)
inlinestaticconstevalprotected

Map welder's neutral welder::rv_kind to pybind11's return_value_policy.

pybind11 has no analogue of nanobind's none, so rv_kind::none is rejected at the bind site (a static_assert in _def_function) rather than mapped here; it falls through to automatic only to keep this total.

Parameters
kthe neutral policy.
Returns
the pybind11 policy.

Definition at line 131 of file rod.hpp.

Referenced by _def_function().

◆ add_constructors()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, auto Ctors, bool HasDefault, bool Aggregate>
void welder::rods::pybind11::rod< DocStyle >::add_constructors ( auto & cls)
inlinestatic

Bind T's whole constructor set (a chained-def framework just loops it): the default constructor when HasDefault, a py::init<…> per member of Ctors, and the synthesized aggregate field constructor when Aggregate.

See also
_def_init
_def_aggregate_init
welder::rod

Definition at line 402 of file rod.hpp.

References _def_aggregate_init(), _def_init(), and welder::detail::aggregate_fields().

◆ add_enumerator()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Enum, class Style = ::welder::naming::none>
void welder::rods::pybind11::rod< DocStyle >::add_enumerator ( auto & e)
inlinestatic

Add enumerator Enum to the enum handle.

See also
welder::rod

Definition at line 588 of file rod.hpp.

References welder::name_of().

◆ add_field()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Mem, class Style = ::welder::naming::none>
void welder::rods::pybind11::rod< DocStyle >::add_field ( auto & cls)
inlinestatic

Bind data member Mem as an attribute.

pybind11 data members are already Python properties (data descriptors on the class), so a [[=welder::doc]] on the member rides along as the property's __doc__ — and thus reaches .pyi stubs. A const member is read-only (def_readonly); a mutable one is read/write (def_readwrite). The doc, when present, is passed as the property docstring. There is deliberately no setter docstring: a Python property surfaces only the getter's __doc__, so one would be pure overhead.

See also
welder::rod

Definition at line 426 of file rod.hpp.

References welder::doc(), welder::doc_of(), and welder::name_of().

◆ add_function()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<auto Fns, class Style = ::welder::naming::none>
py::object welder::rods::pybind11::rod< DocStyle >::add_function ( module_type & m,
const char * name = nullptr )
inlinestatic

Bind free-function overload group Fns as one module-level function (name from Fns[0]; one chained .def per overload).

A non-null name overrides the resolved name (including any weld_as), used verbatim; nullptr falls back to the styled/weld_as name.

Returns
the bound function object (m.attr(name)) — the handle for further hand-registration.
See also
welder::rod

Definition at line 624 of file rod.hpp.

References _def_function(), welder::function, language, and welder::name_of_or().

◆ add_method()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<auto Fns, class Style = ::welder::naming::none>
void welder::rods::pybind11::rod< DocStyle >::add_method ( auto & cls)
inlinestatic

Bind method overload group Fns (name from Fns[0]; pybind11 chains one .def per overload and dispatches at call time).

See also
welder::rod

Definition at line 471 of file rod.hpp.

References _def_function(), and welder::name_of().

◆ add_operator()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<auto Fns>
void welder::rods::pybind11::rod< DocStyle >::add_operator ( auto & cls)
inlinestatic

Bind operator overload group Fns under its Python dunder (one operator + arity per group, so Fns[0] names the slot).

See also
welder::rod

Definition at line 497 of file rod.hpp.

References _def_function(), and welder::rods::python::operator_dunder().

◆ add_static_method()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<auto Fns, class Style = ::welder::naming::none>
void welder::rods::pybind11::rod< DocStyle >::add_static_method ( auto & cls)
inlinestatic

Bind static-method overload group Fns.

See also
welder::rod

Definition at line 483 of file rod.hpp.

References _def_function(), language, welder::name_of(), and welder::static_method.

◆ add_submodule()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
module_type welder::rods::pybind11::rod< DocStyle >::add_submodule ( module_type & m,
const char * name )
inlinestatic

Create a submodule named name under m.

See also
welder::rod

Definition at line 663 of file rod.hpp.

◆ add_variable()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<std::meta::info Var, class Style = ::welder::naming::none>
void welder::rods::pybind11::rod< DocStyle >::add_variable ( module_type & m,
py::dict & live,
const char * name_override = nullptr )
inlinestatic

Bind namespace variable Var as a module attribute.

A const/constexpr variable becomes a value snapshot; a mutable one becomes a live get/set property over the C++ global (accumulated in live). A non-null name_override is used verbatim (beating any weld_as); nullptr falls back to the styled/weld_as name.

See also
welder::rod

Definition at line 642 of file rod.hpp.

References welder::name_of_or().

◆ close_module()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
void welder::rods::pybind11::rod< DocStyle >::close_module ( module_type & m,
py::dict & live )
inlinestatic

Close the session: apply any accumulated live properties.

See also
welder::rod

Definition at line 668 of file rod.hpp.

References _install_live_properties().

◆ finish_enum()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class E>
void welder::rods::pybind11::rod< DocStyle >::finish_enum ( auto & e)
inlinestatic

Finalize enum E: export an unscoped enum's values into the enclosing scope, then commit the enum to the module.

See also
welder::rod

Definition at line 597 of file rod.hpp.

◆ make_class()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, auto Bases, std::size_t... I>
auto welder::rods::pybind11::rod< DocStyle >::make_class ( module_type & m,
const char * name,
const char * doc,
std::index_sequence< I... > seq )
inlinestatic

Create the py::class_<T, Bases…> handle, weaving in a trampoline when T is a welded virtual type with a registered welder::rods::python::trampoline_for.

A type carrying virtual methods is bound overridable — it must register a trampoline (so Python subclasses can override those virtuals) or opt out with [[=welder::rods::python::bind_flat]]. When a trampoline is present, its coverage of T's virtuals is checked at compile time.

See also
_make_class
welder::rods::python::trampoline_for
welder::rod

Definition at line 381 of file rod.hpp.

References _make_class_at(), and welder::doc().

◆ make_enum()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class E>
enum_handle< E > welder::rods::pybind11::rod< DocStyle >::make_enum ( module_type & m,
const char * name,
const char * doc )
inlinestatic

Create the enum_handle for E (a non-null doc becomes its docstring).

See also
welder::rod

Definition at line 564 of file rod.hpp.

References welder::doc().

◆ make_nested_class()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T, auto Bases, std::size_t... I>
auto welder::rods::pybind11::rod< DocStyle >::make_nested_class ( module_type & ,
auto & outer_cls,
const char * name,
const char * doc,
std::index_sequence< I... > seq )
inlinestatic

Create the py::class_ for a nested member type T, registered under its enclosing type's class handle rather than the module — Python then sees it as module.Outer.Inner (and __qualname__ nests), exactly like a hand-written py::class_<Outer::Inner>(outer_cls, "Inner").

Same trampoline weaving as make_class.

See also
welder::rod

Definition at line 392 of file rod.hpp.

References _make_class_at(), and welder::doc().

◆ make_nested_enum()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class E>
enum_handle< E > welder::rods::pybind11::rod< DocStyle >::make_nested_enum ( module_type & ,
auto & outer_cls,
const char * name,
const char * doc )
inlinestatic

Create the enum_handle for a nested member enum E, scoped to its enclosing type's class handle — Python sees module.Outer.Mode, and an unscoped* nested enum's export_values() lands its enumerators on the class (mirroring C++'s Outer::red).

See also
welder::rod

Definition at line 578 of file rod.hpp.

References welder::doc().

◆ open_module()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
py::dict welder::rods::pybind11::rod< DocStyle >::open_module ( module_type & )
inlinestatic

Open a per-module session: a dict accumulating live (mutable-variable) properties; _install_live_properties() applies them in one __class__ swap at close.

See also
welder::rod

Definition at line 611 of file rod.hpp.

◆ set_module_doc()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
void welder::rods::pybind11::rod< DocStyle >::set_module_doc ( module_type & m,
const char * doc )
inlinestatic

Set the (sub)module docstring.

See also
welder::rod

Definition at line 614 of file rod.hpp.

References welder::doc().

◆ special_method_name()

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
consteval const char * welder::rods::pybind11::rod< DocStyle >::special_method_name ( std::meta::info op_fn)
inlinestaticconsteval

Map a member operator to its Python dunder (nullptr = not exposed).

See also
welder::rod

Definition at line 357 of file rod.hpp.

Member Data Documentation

◆ _needs_registration

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T>
bool welder::rods::pybind11::rod< DocStyle >::_needs_registration
staticconstexprprotected
Initial value:
=
std::is_enum_v<std::remove_cvref_t<T>> ||
std::is_base_of_v<py::detail::type_caster_base<py::detail::intrinsic_t<T>>,
py::detail::make_caster<T>>

Whether pybind11 can only convert T via runtime class registration.

True iff T's caster is (or derives from) the generic type_caster_base fallback, which looks T up in pybind11's registered-types map. True for program-defined classes and enums; false for scalars, strings and the pybind11 wrapper types (py::object, py::dict, …). This is the one bindability fact welder's core cannot know on its own; it drives has_native_caster below.

Two things it deliberately does NOT see through — both making it conservative* (it may over-report needs-registration, never under-report):

  • It reads T's caster type at compile time, so it reports whether T needs* a class_/native_enum — never whether one will actually exist at runtime. A class the user hand-registers with py::class_ (or a third-party library registers) but does not weld still reads true, so welder requires welded_for and rejects it: a false positive, resolved by the deferred trust_bindable escape hatch, since the out-of-band registration is invisible here.
  • "native" is relative to the TU's includes: std::complex / std::function / std::chrono / std::filesystem::path are native only when their converter header (<pybind11/complex.h>, functional.h, chrono.h, stl/filesystem.h) is included; otherwise they fall to the class-registration fallback. That is correct — without the header pybind11 genuinely cannot convert them.

A user type_caster is trusted (reads false) only when it is self-contained* — it does not itself derive from type_caster_base (e.g. a PYBIND11_TYPE_CASTER caster). One that derives from type_caster_base still needs T registered, so it correctly still reads true.

Enums are forced into the needs-registration bucket**: pybind11 3's dedicated enum caster does not derive type_caster_base, but it converts only once the enum is registered (py::native_enum / legacy py::enum_) — an unregistered enum raises at call time and renders raw C++ names in docstrings/stubs. Forcing it keeps welder's gate honest (a welded enum's registration is required) and matches every other rod.

Template Parameters
Tthe type whose caster to classify.

Definition at line 118 of file rod.hpp.

◆ has_native_caster

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
template<class T>
bool welder::rods::pybind11::rod< DocStyle >::has_native_caster = !_needs_registration<T>
staticconstexpr

caster_oracle: T is convertible without welder registering a class for it iff pybind11 does not fall back to runtime class registration.

Template Parameters
Tthe type to classify.
See also
welder::caster_oracle

Definition at line 353 of file rod.hpp.

◆ language

template<::welder::doc_style DocStyle = ::welder::rods::python::google_style>
lang welder::rods::pybind11::rod< DocStyle >::language {lang::py}
staticconstexpr

welder::lang::py.

Definition at line 72 of file rod.hpp.

Referenced by _def_function(), add_function(), and add_static_method().


The documentation for this struct was generated from the following file:
  • src/welder/rods/python/pybind11/rod.hpp