@@ -176,11 +176,13 @@ struct argument_record {
176
176
const char *name; // /< Argument name
177
177
const char *descr; // /< Human-readable version of the argument value
178
178
handle value; // /< Associated Python object
179
- bool convert : 1 ; // /< True if the argument is allowed to convert when loading
180
- bool none : 1 ; // /< True if None is allowed when loading
179
+ from_python_policies policies;
181
180
182
- argument_record (const char *name, const char *descr, handle value, bool convert, bool none)
183
- : name(name), descr(descr), value(value), convert(convert), none(none) {}
181
+ argument_record (const char *name,
182
+ const char *descr,
183
+ handle value,
184
+ const from_python_policies &policies)
185
+ : name(name), descr(descr), value(value), policies(policies) {}
184
186
};
185
187
186
188
// / Internal data structure which holds metadata about a bound function (signature, overloads,
@@ -212,8 +214,8 @@ struct function_record {
212
214
// / Pointer to custom destructor for 'data' (if needed)
213
215
void (*free_data)(function_record *ptr) = nullptr ;
214
216
215
- // / Return value policy associated with this function
216
- return_value_policy policy = return_value_policy::automatic ;
217
+ // / Return value policies associated with this function
218
+ return_value_policy_pack rvpp ;
217
219
218
220
// / True if name == '__init__'
219
221
bool is_constructor : 1 ;
@@ -359,7 +361,7 @@ struct type_record {
359
361
360
362
inline function_call::function_call (const function_record &f, handle p) : func(f), parent(p) {
361
363
args.reserve (f.nargs );
362
- args_convert .reserve (f.nargs );
364
+ args_policies .reserve (f.nargs );
363
365
}
364
366
365
367
// / Tag for a new-style `__init__` defined in `detail/init.h`
@@ -407,7 +409,12 @@ struct process_attribute<char *> : process_attribute<const char *> {};
407
409
// / Process an attribute indicating the function's return value policy
408
410
template <>
409
411
struct process_attribute <return_value_policy> : process_attribute_default<return_value_policy> {
410
- static void init (const return_value_policy &p, function_record *r) { r->policy = p; }
412
+ static void init (const return_value_policy &p, function_record *r) { r->rvpp .policy = p; }
413
+ };
414
+ template <>
415
+ struct process_attribute <return_value_policy_pack>
416
+ : process_attribute_default<return_value_policy_pack> {
417
+ static void init (const return_value_policy_pack &rvpp, function_record *r) { r->rvpp = rvpp; }
411
418
};
412
419
413
420
// / Process an attribute which indicates that this is an overloaded function associated with a
@@ -455,7 +462,8 @@ inline void check_kw_only_arg(const arg &a, function_record *r) {
455
462
456
463
inline void append_self_arg_if_needed (function_record *r) {
457
464
if (r->is_method && r->args .empty ()) {
458
- r->args .emplace_back (" self" , nullptr , handle (), /* convert=*/ true , /* none=*/ false );
465
+ r->args .emplace_back (
466
+ " self" , nullptr , handle (), from_python_policies (/* convert=*/ true , /* none=*/ false ));
459
467
}
460
468
}
461
469
@@ -464,19 +472,27 @@ template <>
464
472
struct process_attribute <arg> : process_attribute_default<arg> {
465
473
static void init (const arg &a, function_record *r) {
466
474
append_self_arg_if_needed (r);
467
- r->args .emplace_back (a.name , nullptr , handle (), !a.flag_noconvert , a.flag_none );
475
+ r->args .emplace_back (
476
+ a.name ,
477
+ nullptr ,
478
+ handle (),
479
+ from_python_policies (a.m_policies .rvpp , !a.flag_noconvert , a.flag_none ));
468
480
469
481
check_kw_only_arg (a, r);
470
482
}
471
483
};
484
+ template <>
485
+ struct process_attribute <detail::arg_base> : process_attribute<arg> {};
472
486
473
487
// / Process a keyword argument attribute (*with* a default value)
474
488
template <>
475
489
struct process_attribute <arg_v> : process_attribute_default<arg_v> {
476
490
static void init (const arg_v &a, function_record *r) {
477
491
if (r->is_method && r->args .empty ()) {
478
- r->args .emplace_back (
479
- " self" , /* descr=*/ nullptr , /* parent=*/ handle (), /* convert=*/ true , /* none=*/ false );
492
+ r->args .emplace_back (" self" ,
493
+ /* descr=*/ nullptr ,
494
+ /* parent=*/ handle (),
495
+ from_python_policies (/* convert=*/ true , /* none=*/ false ));
480
496
}
481
497
482
498
if (!a.value ) {
@@ -505,7 +521,11 @@ struct process_attribute<arg_v> : process_attribute_default<arg_v> {
505
521
" more information." );
506
522
#endif
507
523
}
508
- r->args .emplace_back (a.name , a.descr , a.value .inc_ref (), !a.flag_noconvert , a.flag_none );
524
+ r->args .emplace_back (
525
+ a.name ,
526
+ a.descr ,
527
+ a.value .inc_ref (),
528
+ from_python_policies (a.m_policies .rvpp , !a.flag_noconvert , a.flag_none ));
509
529
510
530
check_kw_only_arg (a, r);
511
531
}
@@ -667,7 +687,7 @@ using extract_guard_t = typename exactly_one_t<is_call_guard, call_guard<>, Extr
667
687
668
688
// / Check the number of named arguments at compile time
669
689
template <typename ... Extra,
670
- size_t named = constexpr_sum(std::is_base_of<arg , Extra>::value...),
690
+ size_t named = constexpr_sum(std::is_base_of<arg_base , Extra>::value...),
671
691
size_t self = constexpr_sum(std::is_same<is_method, Extra>::value...)>
672
692
constexpr bool expected_num_args (size_t nargs, bool has_args, bool has_kwargs) {
673
693
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100 (nargs, has_args, has_kwargs);
0 commit comments