Library of Assembled Shared Sources
lass::python::methods Namespace Reference

Detailed Description

Predefined constants for Python special methods (magic methods) that can be used as method names in class export macros.

Available categories:

  • Object Protocol: _call_, _repr_, _str_
  • Numeric Protocol: _add_, _sub_, _mul_, _neg_, _pos_, etc.
  • Comparison Protocol: _lt_, _le_, _eq_, _ne_, _gt_, _ge_
  • Sequence Protocol: _len_, _getitem_, _setitem_, _contains_, etc.
  • Mapping Protocol: map_len_, map_getitem_, map_setitem_
  • Iterator Protocol: _iter_, next
Note
For these special methods to work correctly, you must use the constants defined in the lass::python::methods namespace. Using string literals like "__add__" will not work correctly.

Functions

const lass::python::impl::ArgKwSlot _call_ ("__call__", Py_tp_call)
 __call__ method (callable semantics)
 
const lass::python::impl::UnarySlot _repr_ ("__repr__", Py_tp_repr)
 __repr__ method (must always return a string)
 
const lass::python::impl::UnarySlot _str_ ("__str__", Py_tp_str)
 __str__ method (must always return a string)
 
const lass::python::impl::UnarySlot _neg_ ("__neg__", Py_nb_negative)
 __neg__ method (unary negation)
 
const lass::python::impl::UnarySlot _pos_ ("__pos__", Py_nb_positive)
 __pos__ method (unary positive)
 
const lass::python::impl::UnarySlot _abs_ ("__abs__", Py_nb_absolute)
 __abs__ method (absolute value)
 
const lass::python::impl::UnarySlot _invert_ ("__invert__", Py_nb_invert)
 __invert__ method (bitwise inversion)
 
const lass::python::impl::UnarySlot _int_ ("__int__", Py_nb_int)
 __int__ method (must return an integer)
 
const lass::python::impl::UnarySlot _long_ ("__long__", Py_nb_int)
 alias for __int__ method
 
const lass::python::impl::UnarySlot _float_ ("__float__", Py_nb_float)
 __float__ method (must return a float)
 
const lass::python::impl::BinarySlot _add_ ("__add__", Py_nb_add)
 __add__ method (binary addition)
 
const lass::python::impl::BinarySlot _sub_ ("__sub__", Py_nb_subtract)
 __sub__ method (binary subtraction)
 
const lass::python::impl::BinarySlot _mul_ ("__mul__", Py_nb_multiply)
 __mul__ method (binary multiplication)
 
const lass::python::impl::BinarySlot _mod_ ("__mod__", Py_nb_remainder)
 __mod__ method (modulus)
 
const lass::python::impl::BinarySlot _lshift_ ("__lshift__", Py_nb_lshift)
 __lshift__ method (left shift)
 
const lass::python::impl::BinarySlot _rshift_ ("__rshift__", Py_nb_rshift)
 __rshift__ method (right shift)
 
const lass::python::impl::BinarySlot _and_ ("__and__", Py_nb_and)
 __and__ method (bitwise and)
 
const lass::python::impl::BinarySlot _xor_ ("__xor__", Py_nb_xor)
 __xor__ method (bitwise xor)
 
const lass::python::impl::BinarySlot _or_ ("__or__", Py_nb_or)
 __or__ method (bitwise or)
 
const lass::python::impl::BinarySlot _iadd_ ("__iadd__", Py_nb_inplace_add)
 __iadd__ method (in-place addition)
 
const lass::python::impl::BinarySlot _isub_ ("__isub__", Py_nb_inplace_subtract)
 __isub__ method (in-place subtraction)
 
const lass::python::impl::BinarySlot _imul_ ("__imul__", Py_nb_inplace_multiply)
 __imul__ method (in-place multiplication)
 
const lass::python::impl::BinarySlot _imod_ ("__imod__", Py_nb_inplace_remainder)
 __imod__ method (in-place modulus)
 
const lass::python::impl::BinarySlot _ilshift_ ("__ilshift__", Py_nb_inplace_lshift)
 __ilshift__ method (in-place left shift)
 
const lass::python::impl::BinarySlot _irshift_ ("__irshift__", Py_nb_inplace_rshift)
 __irshift__ method (in-place right shift)
 
const lass::python::impl::BinarySlot _iand_ ("__iand__", Py_nb_inplace_and)
 __iand__ method (in-place bitwise and)
 
const lass::python::impl::BinarySlot _ixor_ ("__ixor__", Py_nb_inplace_xor)
 __ixor__ method (in-place bitwise xor)
 
const lass::python::impl::BinarySlot _ior_ ("__ior__", Py_nb_inplace_or)
 __ior__ method (in-place bitwise or)
 
const lass::python::impl::BinarySlot _truediv_ ("__truediv__", Py_nb_true_divide)
 __truediv__ method (true division)
 
const lass::python::impl::BinarySlot _itruediv_ ("__itruediv__", Py_nb_inplace_true_divide)
 __itruediv__ method (in-place true division)
 
const lass::python::impl::BinarySlot _floordiv_ ("__floordiv__", Py_nb_floor_divide)
 __floordiv__ method (floor division)
 
const lass::python::impl::BinarySlot _ifloordiv_ ("__ifloordiv__", Py_nb_inplace_floor_divide)
 __ifloordiv__ method (in-place floor division)
 
const lass::python::impl::BinarySlot _matmul_ ("__matmul__", Py_nb_matrix_multiply)
 __matmul__ method (matrix multiplication)
 
const lass::python::impl::BinarySlot _imatmul_ ("__imatmul__", Py_nb_inplace_matrix_multiply)
 __imatmul__ method (in-place matrix multiplication)
 
const lass::python::impl::InquirySlot _bool_ ("__bool__", Py_nb_bool)
 __bool__ method (boolean conversion)
 
const lass::python::impl::TernarySlot _pow_ ("__pow__", Py_nb_power)
 __pow__ method (exponentiation)
 
const lass::python::impl::TernarySlot _ipow_ ("__ipow__", Py_nb_inplace_power)
 __ipow__ method (in-place exponentiation)
 
const lass::python::impl::ComparatorSlot _lt_ ("__lt__", Py_LT)
 __lt__ method (less than)
 
const lass::python::impl::ComparatorSlot _le_ ("__le__", Py_LE)
 __le__ method (less than or equal)
 
const lass::python::impl::ComparatorSlot _eq_ ("__eq__", Py_EQ)
 __eq__ method (equal)
 
const lass::python::impl::ComparatorSlot _ne_ ("__ne__", Py_NE)
 __ne__ method (not equal)
 
const lass::python::impl::ComparatorSlot _gt_ ("__gt__", Py_GT)
 __gt__ method (greater than)
 
const lass::python::impl::ComparatorSlot _ge_ ("__ge__", Py_GE)
 __ge__ method (greater than or equal)
 
const lass::python::impl::LenSlot _len_ ("__seq_len__", Py_sq_length)
 __len__ method (length of the sequence)
 
const lass::python::impl::SsizeArgSlot _getitem_ ("__seq_getitem__", Py_sq_item)
 __getitem__ method (get item by index)
 
const lass::python::impl::SsizeObjArgSlot _setitem_ ("__seq_setitem__", Py_sq_ass_item)
 __setitem__ method (set item by index)
 
const lass::python::impl::LenSlot seq_len_ ("__seq_len__", Py_sq_length)
 __len__ method (length of the sequence)
 
const lass::python::impl::BinarySlot _concat_ ("__concat__", Py_sq_concat)
 __concat__ method (concatenation)
 
const lass::python::impl::SsizeArgSlot _repeat_ ("__repeat__", Py_sq_repeat)
 __repeat__ method (repetition)
 
const lass::python::impl::SsizeArgSlot seq_getitem_ ("__seq_getitem__", Py_sq_item)
 __getitem__ method (get item by index)
 
const lass::python::impl::SsizeObjArgSlot seq_setitem_ ("__seq_setitem__", Py_sq_ass_item)
 __setitem__ method (set item by index)
 
const lass::python::impl::ObjObjSlot _contains_ ("__contains__", Py_sq_contains)
 __contains__ method (membership test)
 
const lass::python::impl::BinarySlot _iconcat_ ("__iconcat__", Py_sq_inplace_concat)
 __iconcat__ method (in-place concatenation)
 
const lass::python::impl::SsizeArgSlot _irepeat_ ("__irepeat__", Py_sq_inplace_repeat)
 __irepeat__ method (in-place repetition)
 
const lass::python::impl::LenSlot map_len_ ("__map_len__", Py_mp_length)
 __len__ method (length of the mapping)
 
const lass::python::impl::BinarySlot map_getitem_ ("__map_getitem__", Py_mp_subscript)
 __getitem__ method (get item by key)
 
const lass::python::impl::ObjObjArgSlot map_setitem_ ("__map_setitem__", Py_mp_ass_subscript)
 __setitem__ method (set item by key)
 
const lass::python::impl::IterSlot _iter_ ("__iter__", Py_tp_iter)
 __iter__ method (iterator)
 
const lass::python::impl::IterNextSlot next ("__next__", Py_tp_iternext)
 __next__ method (iterator next)
 

Variables

const lass::python::impl::InquirySlot _nonzero_ = _bool_
 alias for __bool__ method
 
const lass::python::impl::ObjObjArgSlot map_delitem_ = map_setitem_
 __delitem__ method (delete item by key, shares same slot as __setitem__)