39 template <
typename T>
struct base {
40 PYBIND11_DEPRECATED(
"base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
45 template <
size_t Nurse,
size_t Patient>
struct keep_alive { };
98 "The guard type must be default constructible");
103 template <
typename T,
typename... Ts>
118 template <op_
id id, op_type ot,
typename L = undefined_t,
typename R = undefined_t>
struct op_;
130 : name(name), descr(descr), value(value), convert(convert), none(none) { }
146 char *signature =
nullptr;
149 std::vector<argument_record>
args;
188 PyMethodDef *def =
nullptr;
213 const std::type_info *
type =
nullptr;
216 size_t type_size = 0;
219 size_t type_align = 0;
222 size_t holder_size = 0;
228 void (*init_instance)(
instance *,
const void *) =
nullptr;
237 const char *
doc =
nullptr;
258 auto base_info = detail::get_type_info(base,
false);
260 std::string tname(base.name());
261 detail::clean_type_id(tname);
262 pybind11_fail(
"generic_type: type \"" + std::string(name) +
263 "\" referenced unknown base type \"" + tname +
"\"");
266 if (default_holder != base_info->default_holder) {
267 std::string tname(base.name());
268 detail::clean_type_id(tname);
269 pybind11_fail(
"generic_type: type \"" + std::string(name) +
"\" " +
270 (default_holder ?
"does not have" :
"has") +
271 " a non-default holder type while its base \"" + tname +
"\" " +
272 (base_info->default_holder ?
"does not" :
"does"));
275 bases.append((PyObject *) base_info->type);
277 if (base_info->type->tp_dictoffset != 0)
281 base_info->implicit_casts.emplace_back(type, caster);
360 r->
args.emplace_back(
"self",
nullptr,
handle(),
true ,
false );
369 r->
args.emplace_back(
"self",
nullptr ,
handle() ,
true ,
false );
373 std::string
descr(
"'");
374 if (a.
name) descr += std::string(a.
name) +
": ";
375 descr += a.
type +
"'";
378 descr +=
" in method '" + (std::string)
str(r->
scope) +
"." + (std::string) r->
name +
"'";
380 descr +=
" in method of '" + (std::string)
str(r->
scope) +
"'";
381 }
else if (r->
name) {
382 descr +=
" in function '" + (std::string) r->
name +
"'";
384 pybind11_fail(
"arg(): could not convert default argument " 385 + descr +
" into a Python object (type not registered yet?)");
387 pybind11_fail(
"arg(): could not convert default argument " 388 "into a Python object (type not registered yet?). " 389 "Compile in debug mode for more information.");
397 template <
typename T>
403 template <
typename T>
438 template <
typename... Ts>
447 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
449 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N != 0 && P != 0,
int> = 0>
451 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
453 template <
size_t N = Nurse,
size_t P = Patient, enable_if_t<N == 0 || P == 0,
int> = 0>
477 template <
typename T>
481 template <
typename... Extra>
485 template <
typename... Extra,
489 return named == 0 || (
self + named + has_args + has_kwargs) == nargs;
static void init(const dynamic_attr &, type_record *r)
std::uint16_t nargs
Number of arguments (including py::args and/or py::kwargs, if present)
static void init(const handle &h, type_record *r)
Type for an unused type slot.
static void init(const name &n, function_record *r)
static void init(const is_new_style_constructor &, function_record *r)
bool has_kwargs
True if the function has a '**kwargs' argument.
Annotation for parent scope.
static void precall(function_call &)
Operator implementation generator.
#define PYBIND11_NAMESPACE
PyObject * ptr() const
Return the underlying PyObject * pointer.
return_value_policy policy
Return value policy associated with this function.
constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs)
Check the number of named arguments at compile time.
Tag for a new-style __init__ defined in detail/init.h
bool is_constructor
True if name == 'init'.
handle sibling
Python handle to the sibling function representing an overload chain.
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
bool flag_noconvert
If set, do not allow conversion (requires a supporting type caster!)
static void init(const multiple_inheritance &, type_record *r)
const char * name
If non-null, this is a named kwargs argument.
static void init(const Args &... args, function_record *r)
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
std::string type
The C++ type name of the default value (only available when compiled in debug mode) ...
is_method(const handle &c)
Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
Internal data associated with a single function call.
static void init(const doc &n, function_record *r)
bool is_stateless
True if this is a stateless function pointer.
test_initializer class_("class_", test_submodule_class_)
const char * name
Argument name.
arr data(const arr &a, Ix... index)
Annotation which enables dynamic attributes, i.e. adds __dict__ to a class.
#define PYBIND11_NOINLINE
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') ...
static void init(const base< T > &, type_record *r)
static void init(const is_method &s, function_record *r)
Internal data structure which holds metadata about a keyword argument.
Recursively iterate over variadic template arguments.
size_t function_call handle ret
static void postcall(function_call &call, handle ret)
handle scope
Python handle to the parent scope (a class or a module)
static void init(const arg &a, function_record *r)
bool none
True if None is allowed when loading.
handle metaclass
Custom metaclass (optional)
handle scope
Handle to the parent scope.
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
static void init(const buffer_protocol &, type_record *r)
#define NAMESPACE_END(name)
const char * descr
The (optional) description of the default value.
argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
static void init(const module_local &l, type_record *r)
static void init(const T &, function_record *)
Default implementation: do nothing.
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) ...
bool module_local
Is the class definition local to the module shared object?
static void init(const char *d, type_record *r)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
static void postcall(function_call &, handle)
Annotation indicating that a function is an overload associated with a given "sibling".
object value
The default value.
bool multiple_inheritance
Multiple inheritance marker.
bool is_method
True if this is a method.
Process an attribute specifying the function's docstring (provided as a C-style string) ...
bool buffer_protocol
Does the class implement the buffer protocol?
size_t function_call & call
static void init(const sibling &s, function_record *r)
Annotation for operators.
Annotation to mark enums as an arithmetic type.
char * name
Function name.
constexpr size_t constexpr_sum()
Compile-time integer sum.
Keep patient alive while nurse lives.
static void precall(function_call &call)
static void precall(function_call &)
bool default_holder
Is the default (unique_ptr) holder type used?
bool dynamic_attr
Does the class manage a dict?
static void init(const char *d, function_record *r)
Annotation for documentation.
op_id
Enumeration with all supported operator types.
Annotation which enables the buffer protocol for a type.
static void postcall(function_call &call, handle fn_ret)
static void init(const scope &s, function_record *r)
static void init(const arg_v &a, function_record *r)
static void init(const T &, type_record *)
Annotation indicating that a class derives from another given type.
const detail::type_info * type
Annotation for function names.
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
Helper type to replace 'void' in some expressions.
static void init(const return_value_policy &p, function_record *r)
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
#define PYBIND11_DEPRECATED(reason)
void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret)
static void precall(function_call &call)
bool convert
True if the argument is allowed to convert when loading.
#define NAMESPACE_BEGIN(name)
const char * doc
Optional docstring.
bool is_new_style_constructor
True if this is a new-style __init__ defined in detail/init.h
std::vector< argument_record > args
List of registered keyword arguments.
handle value
Associated Python object.
static void init(const Args &... args, type_record *r)
Special data structure which (temporarily) holds metadata about a bound class.
list bases
List of base classes of the newly created type.
static void init(const is_operator &, function_record *r)
bool flag_none
If set (the default), allow None to be passed to this argument.
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
const handle & inc_ref() const &
bool is_operator
True if this is an operator (add), etc.
Annotation that marks a class as local to the module:
const char * descr
Human-readable version of the argument value.
bool has_args
True if the function has a '*args' argument.
Annotation indicating that a class is involved in a multiple inheritance relationship.
static void postcall(function_call &, handle)