Merge branch 'm7thon-python23-division-operators'
* m7thon-python23-division-operators: [Python] improved wrapping of division operators
This commit is contained in:
commit
1079ba7ff8
1 changed files with 22 additions and 10 deletions
|
|
@ -108,11 +108,6 @@
|
||||||
%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
|
%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
|
||||||
%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
|
%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
|
||||||
%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
|
%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
|
||||||
#if defined(SWIGPYTHON_PY3)
|
|
||||||
%pybinoperator(__truediv__, *::operator/, binaryfunc, nb_divide);
|
|
||||||
#else
|
|
||||||
%pybinoperator(__div__, *::operator/, binaryfunc, nb_divide);
|
|
||||||
#endif
|
|
||||||
%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
|
%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
|
||||||
%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
|
%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
|
||||||
%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
|
%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
|
||||||
|
|
@ -134,6 +129,7 @@
|
||||||
|
|
||||||
#if defined(SWIGPYTHON_BUILTIN)
|
#if defined(SWIGPYTHON_BUILTIN)
|
||||||
%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero);
|
%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero);
|
||||||
|
%pybinoperator(__truediv__, *::operator/ , binaryfunc, nb_divide);
|
||||||
#else
|
#else
|
||||||
%feature("shadow") *::operator bool %{
|
%feature("shadow") *::operator bool %{
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
|
|
@ -141,6 +137,13 @@ def __nonzero__(self):
|
||||||
__bool__ = __nonzero__
|
__bool__ = __nonzero__
|
||||||
%};
|
%};
|
||||||
%rename(__nonzero__) *::operator bool;
|
%rename(__nonzero__) *::operator bool;
|
||||||
|
%feature("shadow") *::operator/ %{
|
||||||
|
def __truediv__(self, *args):
|
||||||
|
return $action(self, *args)
|
||||||
|
__div__ = __truediv__
|
||||||
|
%};
|
||||||
|
%rename(__truediv__) *::operator/;
|
||||||
|
%pythonmaybecall *::operator/;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Ignored operators */
|
/* Ignored operators */
|
||||||
|
|
@ -207,11 +210,6 @@ __bool__ = __nonzero__
|
||||||
%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
|
%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
|
||||||
%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
|
%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
|
||||||
%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
|
%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
|
||||||
#if defined(SWIGPYTHON_PY3)
|
|
||||||
%pyinplaceoper(__itruediv__ , *::operator /=, binaryfunc, nb_inplace_divide);
|
|
||||||
#else
|
|
||||||
%pyinplaceoper(__idiv__ , *::operator /=, binaryfunc, nb_inplace_divide);
|
|
||||||
#endif
|
|
||||||
%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
|
%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
|
||||||
%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
|
%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
|
||||||
%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
|
%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
|
||||||
|
|
@ -219,6 +217,19 @@ __bool__ = __nonzero__
|
||||||
%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
|
%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
|
||||||
%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
|
%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
|
||||||
|
|
||||||
|
/* Special cases */
|
||||||
|
#if defined(SWIGPYTHON_BUILTIN)
|
||||||
|
%pyinplaceoper(__itruediv__ , *::operator /=, binaryfunc, nb_inplace_divide);
|
||||||
|
#else
|
||||||
|
%delobject *::operator /=;
|
||||||
|
%newobject *::operator /=;
|
||||||
|
%feature("shadow") *::operator /= %{
|
||||||
|
def __itruediv__(self, *args):
|
||||||
|
return $action(self, *args)
|
||||||
|
__idiv__ = __itruediv__
|
||||||
|
%};
|
||||||
|
%rename(__itruediv__) *::operator /=;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Finally, in python we need to mark the binary operations to fail as
|
/* Finally, in python we need to mark the binary operations to fail as
|
||||||
'maybecall' methods */
|
'maybecall' methods */
|
||||||
|
|
@ -233,6 +244,7 @@ __bool__ = __nonzero__
|
||||||
%pybinopermaybecall(neg);
|
%pybinopermaybecall(neg);
|
||||||
%pybinopermaybecall(mul);
|
%pybinopermaybecall(mul);
|
||||||
%pybinopermaybecall(div);
|
%pybinopermaybecall(div);
|
||||||
|
%pybinopermaybecall(truediv);
|
||||||
%pybinopermaybecall(mod);
|
%pybinopermaybecall(mod);
|
||||||
%pybinopermaybecall(lshift);
|
%pybinopermaybecall(lshift);
|
||||||
%pybinopermaybecall(rshift);
|
%pybinopermaybecall(rshift);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue