42 template <
typename T>
struct base {
44 PYBIND11_DEPRECATED(
"base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
49 template <
size_t Nurse,
size_t Patient>
struct keep_alive { };
64 PYBIND11_DEPRECATED(
"py::metaclass() is no longer required. It's turned on by default now.")
102 "The guard type must be default constructible");
107 template <
typename T,
typename... Ts>
122 template <op_
id id, op_type ot,
typename L = undefined_t,
typename R = undefined_t>
struct op_;
134 : name(name), descr(descr), value(value), convert(convert), none(none) { }
142 has_args(false), has_kwargs(false), has_kw_only_args(false) { }
151 char *signature =
nullptr;
154 std::vector<argument_record>
args;
169 bool is_constructor : 1;
175 bool is_stateless : 1;
190 bool has_kw_only_args : 1;
202 PyMethodDef *def =
nullptr;
227 const std::type_info *
type =
nullptr;
230 size_t type_size = 0;
233 size_t type_align = 0;
236 size_t holder_size = 0;
242 void (*init_instance)(
instance *,
const void *) =
nullptr;
245 void (*dealloc)(detail::value_and_holder &) =
nullptr;
251 const char *
doc =
nullptr;
266 bool default_holder : 1;
277 std::string tname(base.name());
280 "\" referenced unknown base type \"" + tname +
"\"");
283 if (default_holder != base_info->default_holder) {
284 std::string tname(base.name());
286 pybind11_fail(
"generic_type: type \"" + std::string(name) +
"\" " +
287 (default_holder ?
"does not have" :
"has") +
288 " a non-default holder type while its base \"" + tname +
"\" " +
289 (base_info->default_holder ?
"does not" :
"does"));
292 bases.
append((PyObject *) base_info->type);
294 if (base_info->type->tp_dictoffset != 0)
298 base_info->implicit_casts.emplace_back(type, caster);
375 pybind11_fail(
"arg(): cannot specify an unnamed argument after an kw_only() annotation");
383 r->
args.emplace_back(
"self",
nullptr,
handle(),
true ,
false );
394 r->
args.emplace_back(
"self",
nullptr ,
handle() ,
true ,
false );
398 std::string
descr(
"'");
399 if (a.
name) descr += std::string(a.
name) +
": ";
400 descr += a.
type +
"'";
403 descr +=
" in method '" + (std::string)
str(r->
scope) +
"." + (std::string) r->
name +
"'";
405 descr +=
" in method of '" + (std::string)
str(r->
scope) +
"'";
406 }
else if (r->
name) {
407 descr +=
" in function '" + (std::string) r->
name +
"'";
410 + descr +
" into a Python object (type not registered yet?)");
413 "into a Python object (type not registered yet?). " 414 "Compile in debug mode for more information.");
438 template <
typename T>
444 template <
typename T>
484 template <
typename... Ts>
493 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
495 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
497 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
499 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
523 template <
typename T>
527 template <
typename... Extra>
531 template <
typename... Extra,
535 return named == 0 || (
self + named + has_args + has_kwargs) == nargs;
handle scope
Python handle to the parent scope (a class or a module)
static void precall(function_call &)
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
Annotation which enables dynamic attributes, i.e. adds __dict__ to a class.
Annotation for parent scope.
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)
void append(T &&val) const
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.
static void init(const buffer_protocol &, type_record *r)
PyObject * ptr() const
Return the underlying PyObject * pointer.
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.
bool has_kw_only_args
True once a 'py::kw_only' is encountered (any following args are keyword-only)
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.
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 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)
constexpr size_t constexpr_sum()
Compile-time integer sum.
PyExc_RuntimeError[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
static void init(const sibling &s, function_record *r)
const handle & inc_ref() const &
const char * descr
Human-readable version of the argument value.
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:
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.
bool convert(const int &y)
std::uint16_t nargs_kw_only
Number of trailing arguments (counted in nargs) that are keyword-only.
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.
Recursively iterate over variadic template arguments.
#define PYBIND11_DEPRECATED(reason)
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)
static void init(const Args &...args, function_record *r)
Annotation indicating that a class is involved in a multiple inheritance relationship.
Annotation to mark enums as an arithmetic type.
std::is_base_of< pyobject_tag, remove_reference_t< T >> is_pyobject
static void init(const is_operator&, function_record *r)
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.
PYBIND11_NOINLINE detail::type_info * get_type_info(PyTypeObject *type)
void process_kw_only_arg(const arg &a, function_record *r)
static void init(const char *d, function_record *r)
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 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)
Annotation indicating that a function is an overload associated with a given "sibling".
#define PYBIND11_NOINLINE
Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
bool flag_noconvert
If set, do not allow conversion (requires a supporting type caster!)
Internal data structure which holds metadata about a keyword argument.
#define PYBIND11_NAMESPACE_END(name)
std::string type
The C++ type name of the default value (only available when compiled in debug mode) ...
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.