MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / operator_impl

Function operator_impl

src/py_class/py_class_impl.py:697–735  ·  view source on GitHub ↗
(special_name, slot, args, res_type, res_conv, res_ffi_type, additional_slots, typefunc)

Source from the content-addressed store, hash-verified

695 error('Invalid signature for operator %s' % special_name)(special_name)
696
697def operator_impl(special_name, slot, args, res_type, res_conv, res_ffi_type, additional_slots, typefunc):
698 if res_conv is None:
699 if res_type == '()':
700 res_conv = '$crate::py_class::slots::UnitCallbackConverter'
701 res_ffi_type = '$crate::_detail::libc::c_int'
702 elif res_type == 'bool':
703 res_conv = '$crate::py_class::slots::BoolConverter'
704 res_ffi_type = '$crate::_detail::libc::c_int'
705 elif res_type == 'PyObject':
706 res_conv = '$crate::_detail::PyObjectCallbackConverter'
707 else:
708 res_conv = '$crate::_detail::PythonObjectCallbackConverter::<$crate::%s>(std::marker::PhantomData)' % res_type
709 arg_pattern = ''
710 param_list = []
711 for arg in args:
712 arg_pattern += ', ${0}:ident : {1}'.format(arg.name, typefunc(arg, ":ty"))
713 param_list.append('{{ ${0} : {1} = {{}} }}'.format(arg.name, typefunc(arg)))
714 if slot == 'sq_contains':
715 new_slots = [(slot, '$crate::py_class_contains_slot!($class::%s, [%s])' % (special_name, typefunc(args[0])))]
716 elif slot == 'tp_richcompare':
717 new_slots = [(slot, '$crate::py_class_richcompare_slot!($class::%s, [%s], %s, %s)'
718 % (special_name, typefunc(args[0]), res_ffi_type, res_conv))]
719 elif len(args) == 0:
720 new_slots = [(slot, '$crate::py_class_unary_slot!($class::%s, %s, %s)'
721 % (special_name, res_ffi_type, res_conv))]
722 elif len(args) == 1:
723 new_slots = [(slot, '$crate::py_class_binary_slot!($class::%s, [%s], %s, %s)'
724 % (special_name, typefunc(args[0]), res_ffi_type, res_conv))]
725 elif len(args) == 2:
726 new_slots = [(slot, '$crate::py_class_ternary_slot!($class::%s, [%s], %s, %s, %s)'
727 % (special_name, typefunc(args[0]), typefunc(args[1]), res_ffi_type, res_conv))]
728 else:
729 raise ValueError('Unsupported argument count')
730 generate_case(
731 pattern='def %s(&$slf:ident%s) -> $res_type:ty { $($body:tt)* }' % (special_name, arg_pattern),
732 new_impl='$crate::py_class_impl_item! { $class, $py, pub, %s(&$slf,) $res_type; { $($body)* } [%s] }'
733 % (special_name, ' '.join(param_list)),
734 new_slots=new_slots + list(additional_slots)
735 )
736
737@special_method
738def call_operator(special_name, slot):

Callers 1

operatorFunction · 0.85

Calls 4

lenFunction · 0.85
generate_caseFunction · 0.85
formatMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected