44 explicit doc(
const char *value) : value(value) {}
50 explicit name(
const char *value) : value(value) {}
64 "base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
69 template <
size_t Nurse,
size_t Patient>
85 PYBIND11_DEPRECATED(
"py::metaclass() is no longer required. It's turned on by default now.")
102 using callback = std::function<void(PyHeapTypeObject *heap_type)>;
139 template <
typename... Ts>
144 using type = detail::void_type;
147 template <
typename T>
150 "The guard type must be default constructible");
155 template <
typename T,
typename... Ts>
170 template <op_
id id, op_type ot,
typename L = undefined_t,
typename R = undefined_t>
183 : name(name), descr(descr), value(value), convert(convert), none(none) {}
201 char *signature =
nullptr;
204 std::vector<argument_record>
args;
253 PyMethodDef *def =
nullptr;
278 const std::type_info *
type =
nullptr;
281 size_t type_size = 0;
284 size_t type_align = 0;
287 size_t holder_size = 0;
293 void (*init_instance)(
instance *,
const void *) =
nullptr;
296 void (*dealloc)(detail::value_and_holder &) =
nullptr;
302 const char *
doc =
nullptr;
331 std::string tname(base.name());
334 +
"\" referenced unknown base type \"" + tname +
"\"");
337 if (default_holder != base_info->default_holder) {
338 std::string tname(base.name());
340 pybind11_fail(
"generic_type: type \"" + std::string(name) +
"\" " 341 + (default_holder ?
"does not have" :
"has")
342 +
" a non-default holder type while its base \"" + tname +
"\" " 343 + (base_info->default_holder ?
"does not" :
"does"));
346 bases.
append((PyObject *) base_info->type);
348 #if PY_VERSION_HEX < 0x030B0000 351 dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;
355 base_info->implicit_casts.emplace_back(type, caster);
374 template <
typename T,
typename SFINAE =
void>
377 template <
typename T>
451 pybind11_fail(
"arg(): cannot specify an unnamed argument after a kw_only() annotation or " 458 r->
args.emplace_back(
"self",
nullptr,
handle(),
true,
false);
478 r->
args.emplace_back(
479 "self",
nullptr,
handle(),
true,
false);
483 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES) 484 std::string
descr(
"'");
486 descr += std::string(a.
name) +
": ";
488 descr += a.
type +
"'";
491 descr +=
" in method '" + (std::string)
str(r->
scope) +
"." 492 + (std::string) r->
name +
"'";
494 descr +=
" in method of '" + (std::string)
str(r->
scope) +
"'";
496 }
else if (r->
name) {
497 descr +=
" in function '" + (std::string) r->
name +
"'";
499 pybind11_fail(
"arg(): could not convert default argument " + descr
500 +
" into a Python object (type not registered yet?)");
503 "into a Python object (type not registered yet?). " 504 "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " 505 "more information.");
520 pybind11_fail(
"Mismatched args() and kw_only(): they must occur at the same relative " 521 "argument location (or omit kw_only() entirely)");
534 pybind11_fail(
"pos_only(): cannot follow a py::args() argument");
542 template <
typename T>
549 template <
typename T>
604 template <
typename... Ts>
612 template <
size_t Nurse,
size_t Patient>
615 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
619 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
621 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
623 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
630 template <
typename... Args>
635 using expander =
int[];
642 using expander =
int[];
648 using expander =
int[];
655 using expander =
int[];
661 template <
typename T>
665 template <
typename... Extra>
669 template <
typename... Extra,
674 return named == 0 || (
self + named +
size_t(has_args) +
size_t(has_kwargs)) == nargs;
handle scope
Python handle to the parent scope (a class or a module)
PYBIND11_NOINLINE detail::type_info * get_type_info(PyTypeObject *type)
static void precall(function_call &)
constexpr module_local(bool v=true)
Annotation which enables dynamic attributes, i.e. adds __dict__ to a class.
void check_kw_only_arg(const arg &a, function_record *r)
Annotation for parent scope.
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
bool is_final
Is the class inheritable from python classes?
std::uint16_t nargs
Number of arguments (including py::args and/or py::kwargs, if present)
Operator implementation generator.
is_method(const handle &c)
PYBIND11_NOINLINE type_record()
static void postcall(function_call &call, handle ret)
Keep patient alive while nurse lives.
static void init(const scope &s, function_record *r)
return_value_policy policy
Return value policy associated with this function.
PYBIND11_DEPRECATED("make_simple_namespace should be replaced with " "py::module_::import(\ypes\.attr(\impleNamespace\ ") object make_simple_namespace(Args &&...args_)
static void init(const buffer_protocol &, type_record *r)
handle sibling
Python handle to the sibling function representing an overload chain.
static void init(const doc &n, function_record *r)
Annotation for documentation.
Tag for a new-style __init__ defined in detail/init.h
Type for an unused type slot.
static void init(const kw_only &, function_record *r)
object value
The default value.
bool buffer_protocol
Does the class implement the buffer protocol?
static void init(const arg_v &a, function_record *r)
static void init(const dynamic_attr &, type_record *r)
argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
const char * doc
Optional docstring.
sibling(const handle &value)
static void init(const custom_type_setup &value, type_record *r)
bool multiple_inheritance
Multiple inheritance marker.
Annotation for operators.
static void postcall(function_call &, handle)
static void postcall(function_call &call, handle fn_ret)
static void init(const prepend &, function_record *r)
static void init(const char *d, type_record *r)
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
static void init(const arg &a, function_record *r)
PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *))
Internal data associated with a single function call.
handle value
Associated Python object.
static void init(const base< T > &, type_record *r)
#define PYBIND11_NAMESPACE
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') ...
op_id
Enumeration with all supported operator types.
Process an attribute specifying the function's docstring (provided as a C-style string) ...
PYBIND11_NOINLINE void clean_type_id(std::string &name)
std::function< void(PyHeapTypeObject *heap_type)> callback
constexpr size_t constexpr_sum()
Compile-time integer sum.
PyExc_RuntimeError [[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
custom_type_setup::callback custom_type_setup_callback
Custom type setup.
static void init(const sibling &s, function_record *r)
const handle & inc_ref() const &
custom_type_setup(callback value)
bool has_kwargs
True if the function has a '**kwargs' argument.
const char * descr
Human-readable version of the argument value.
bool convert
True if the argument is allowed to convert when loading.
handle metaclass
Custom metaclass (optional)
static void init(const module_local &l, type_record *r)
static const Line3 l(Rot3(), 1, 1)
void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret)
const char * name
Argument name.
static void init(const Args &...args, type_record *r)
handle scope
Handle to the parent scope.
static void init(const is_final &, type_record *r)
static void init(const pos_only &, function_record *r)
Annotation that marks a class as local to the module:
bool is_stateless
True if this is a stateless function pointer.
std::uint16_t nargs_pos_only
Number of leading arguments (counted in nargs) that are positional-only.
list bases
List of base classes of the newly created type.
function_call(const function_record &f, handle p)
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
Array< int, Dynamic, 1 > v
static void init(const T &, function_record *)
Default implementation: do nothing.
static void precall(function_call &call)
Eigen::Triplet< double > T
constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs)
Check the number of named arguments at compile time.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
bool is_method
True if this is a method.
bool is_constructor
True if name == 'init'.
Recursively iterate over variadic template arguments.
#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
bool module_local
Is the class definition local to the module shared object?
static void precall(function_call &call)
Annotation which enables the buffer protocol for a type.
static void init(const name &n, function_record *r)
static void init(const T &, type_record *)
static void init(const handle &h, type_record *r)
bool prepend
True if this function is to be inserted at the beginning of the overload resolution chain...
bool none
True if None is allowed when loading.
static void init(const Args &...args, function_record *r)
Annotation indicating that a class is involved in a multiple inheritance relationship.
static void init(const is_operator &, function_record *r)
void append_self_arg_if_needed(function_record *r)
Annotation to mark enums as an arithmetic type.
typename exactly_one_t< is_call_guard, call_guard<>, Extra... >::type extract_guard_t
Extract the type from the first call_guard in Extras... (or void_type if none found) ...
Annotation for classes that cannot be subclassed.
static void init(const is_method &s, function_record *r)
Special data structure which (temporarily) holds metadata about a bound class.
static void init(const char *d, function_record *r)
bool default_holder
Is the default (unique_ptr) holder type used?
static void postcall(function_call &, handle)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
std::vector< argument_record > args
List of registered keyword arguments.
static void init(const return_value_policy &p, function_record *r)
char * name
Function name.
bool has_args
True if the function has a '*args' argument.
bool is_operator
True if this is an operator (add), etc.
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
const char * descr
The (optional) description of the default value.
static void init(const is_new_style_constructor &, function_record *r)
bool is_new_style_constructor
True if this is a new-style __init__ defined in detail/init.h
Annotation for function names.
const char * name
If non-null, this is a named kwargs argument.
Annotation indicating that a class derives from another given type.
static void init(const multiple_inheritance &, type_record *r)
Mark a function for addition at the beginning of the existing overload chain instead of the end...
Annotation indicating that a function is an overload associated with a given "sibling".
#define PYBIND11_NOINLINE
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Internal data structure which holds metadata about a keyword argument.
#define PYBIND11_NAMESPACE_END(name)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
std::string type
The C++ type name of the default value (only available when compiled in debug mode) ...
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
static void precall(function_call &)
bool dynamic_attr
Does the class manage a dict?
#define PYBIND11_NAMESPACE_BEGIN(name)
bool flag_none
If set (the default), allow None to be passed to this argument.