Special Python methods

Table of Contents
PyMethods — Implement additional Python special methods
PyNumberMethods — Implement numerical Python special methods
PySequenceMethods — Implement Python sequence special methods
PyMappingMethods — Implement Python mapping special methods

Python special methods can be implemented but code must be supplied. The above 4 keywords define additional sections in a class declaration (like public, private etc.). Typical sip file section is as follows:

    class X
    {
        ...	
        PyMethods:
            __str__
    %MemberCode
                C++ code (no enclosing braces needed).
                Number and kind of arguments and return value depend on method
                (see specialPyMethod in sip.h).
    %End
        ...
    }

PyMethods

Name

PyMethods -- Implement additional Python special methods

Synopsis

PyMethods

Description

Within this section the following methods are legal:

__repr__, __str__, __cmp__, __hash__, __call__, __richcompare__


PyNumberMethods

Name

PyNumberMethods -- Implement numerical Python special methods

Synopsis

PyNumberMethods

Description

Within this section the following methods are legal:

__add__, __sub__, __mul__, __div__, __mod__, __divmod__, __pow__, __neg__, __pos__, __abs__, __nonzero__, __invert__, __lshift__, __rshift__, __and__, __xor__, __or__, __coerce__, __int__, __long__, __float__, __oct__, __hex__, __iadd__, __isub__, __imul__, __idiv__, __imod__, __ipow__, __ilshift__, __irshift__, __iand__, __ixor__, __ior__


PySequenceMethods

Name

PySequenceMethods -- Implement Python sequence special methods

Synopsis

PySequenceMethods

Description

Within this section the following methods are legal:

__len__, __add__, __mul__, __getitem__, __setitem__, __getslice__, __setslice__, __contains__, __iadd__, __imul__


PyMappingMethods

Name

PyMappingMethods -- Implement Python mapping special methods

Synopsis

PyMappingMethods

Description

Within this section the following methods are legal:

__len__, __getitem__, __setitem__