Commit efc28588 authored by Georg Brandl's avatar Georg Brandl

#7259: show correct equivalent for operator.i* operations in docstring; fix...

#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
parent 4ac6b93c
...@@ -117,6 +117,14 @@ The mathematical and bitwise operations are the most numerous: ...@@ -117,6 +117,14 @@ The mathematical and bitwise operations are the most numerous:
.. versionadded:: 2.2 .. versionadded:: 2.2
.. function:: index(a)
__index__(a)
Return *a* converted to an integer. Equivalent to ``a.__index__()``.
.. versionadded:: 2.5
.. function:: inv(obj) .. function:: inv(obj)
invert(obj) invert(obj)
__inv__(obj) __inv__(obj)
...@@ -149,7 +157,7 @@ The mathematical and bitwise operations are the most numerous: ...@@ -149,7 +157,7 @@ The mathematical and bitwise operations are the most numerous:
.. function:: neg(obj) .. function:: neg(obj)
__neg__(obj) __neg__(obj)
Return *obj* negated. Return *obj* negated (``-obj``).
.. function:: or_(a, b) .. function:: or_(a, b)
...@@ -161,7 +169,7 @@ The mathematical and bitwise operations are the most numerous: ...@@ -161,7 +169,7 @@ The mathematical and bitwise operations are the most numerous:
.. function:: pos(obj) .. function:: pos(obj)
__pos__(obj) __pos__(obj)
Return *obj* positive. Return *obj* positive (``+obj``).
.. function:: pow(a, b) .. function:: pow(a, b)
...@@ -199,15 +207,7 @@ The mathematical and bitwise operations are the most numerous: ...@@ -199,15 +207,7 @@ The mathematical and bitwise operations are the most numerous:
Return the bitwise exclusive or of *a* and *b*. Return the bitwise exclusive or of *a* and *b*.
.. function:: index(a) Operations which work with sequences (some of them with mappings too) include:
__index__(a)
Return *a* converted to an integer. Equivalent to ``a.__index__()``.
.. versionadded:: 2.5
Operations which work with sequences include:
.. function:: concat(a, b) .. function:: concat(a, b)
__concat__(a, b) __concat__(a, b)
...@@ -359,7 +359,7 @@ example, the :term:`statement` ``x += y`` is equivalent to ...@@ -359,7 +359,7 @@ example, the :term:`statement` ``x += y`` is equivalent to
.. function:: ilshift(a, b) .. function:: ilshift(a, b)
__ilshift__(a, b) __ilshift__(a, b)
``a = ilshift(a, b)`` is equivalent to ``a <``\ ``<= b``. ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
.. versionadded:: 2.5 .. versionadded:: 2.5
...@@ -572,79 +572,81 @@ Mapping Operators to Functions ...@@ -572,79 +572,81 @@ Mapping Operators to Functions
This table shows how abstract operations correspond to operator symbols in the This table shows how abstract operations correspond to operator symbols in the
Python syntax and the functions in the :mod:`operator` module. Python syntax and the functions in the :mod:`operator` module.
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Operation | Syntax | Function | | Operation | Syntax | Function |
+=======================+=========================+=================================+ +=======================+=========================+=======================================+
| Addition | ``a + b`` | ``add(a, b)`` | | Addition | ``a + b`` | ``add(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | | Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` | | Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Division | ``a / b`` | ``div(a, b)`` (without | | Division | ``a / b`` | ``div(a, b)`` (without |
| | | ``__future__.division``) | | | | ``__future__.division``) |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Division | ``a / b`` | ``truediv(a, b)`` (with | | Division | ``a / b`` | ``truediv(a, b)`` (with |
| | | ``__future__.division``) | | | | ``__future__.division``) |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Division | ``a // b`` | ``floordiv(a, b)`` | | Division | ``a // b`` | ``floordiv(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Bitwise And | ``a & b`` | ``and_(a, b)`` | | Bitwise And | ``a & b`` | ``and_(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` | | Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Bitwise Inversion | ``~ a`` | ``invert(a)`` | | Bitwise Inversion | ``~ a`` | ``invert(a)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Bitwise Or | ``a | b`` | ``or_(a, b)`` | | Bitwise Or | ``a | b`` | ``or_(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Exponentiation | ``a ** b`` | ``pow(a, b)`` | | Exponentiation | ``a ** b`` | ``pow(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Identity | ``a is b`` | ``is_(a, b)`` | | Identity | ``a is b`` | ``is_(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Identity | ``a is not b`` | ``is_not(a, b)`` | | Identity | ``a is not b`` | ``is_not(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` | | Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` | | Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Indexing | ``obj[k]`` | ``getitem(obj, k)`` | | Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Left Shift | ``a << b`` | ``lshift(a, b)`` | | Left Shift | ``a << b`` | ``lshift(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Modulo | ``a % b`` | ``mod(a, b)`` | | Modulo | ``a % b`` | ``mod(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Multiplication | ``a * b`` | ``mul(a, b)`` | | Multiplication | ``a * b`` | ``mul(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Negation (Arithmetic) | ``- a`` | ``neg(a)`` | | Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Negation (Logical) | ``not a`` | ``not_(a)`` | | Negation (Logical) | ``not a`` | ``not_(a)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Positive | ``+ a`` | ``pos(a)`` |
+-----------------------+-------------------------+---------------------------------------+
| Right Shift | ``a >> b`` | ``rshift(a, b)`` | | Right Shift | ``a >> b`` | ``rshift(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` | | Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Slice Assignment | ``seq[i:j] = values`` | ``setslice(seq, i, j, values)`` | | Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Slice Deletion | ``del seq[i:j]`` | ``delslice(seq, i, j)`` | | Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` | | Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| String Formatting | ``s % obj`` | ``mod(s, obj)`` | | String Formatting | ``s % obj`` | ``mod(s, obj)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Subtraction | ``a - b`` | ``sub(a, b)`` | | Subtraction | ``a - b`` | ``sub(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Truth Test | ``obj`` | ``truth(obj)`` | | Truth Test | ``obj`` | ``truth(obj)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Ordering | ``a < b`` | ``lt(a, b)`` | | Ordering | ``a < b`` | ``lt(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Ordering | ``a <= b`` | ``le(a, b)`` | | Ordering | ``a <= b`` | ``le(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Equality | ``a == b`` | ``eq(a, b)`` | | Equality | ``a == b`` | ``eq(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Difference | ``a != b`` | ``ne(a, b)`` | | Difference | ``a != b`` | ``ne(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Ordering | ``a >= b`` | ``ge(a, b)`` | | Ordering | ``a >= b`` | ``ge(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
| Ordering | ``a > b`` | ``gt(a, b)`` | | Ordering | ``a > b`` | ``gt(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------------+
...@@ -7,7 +7,7 @@ PyDoc_STRVAR(operator_doc, ...@@ -7,7 +7,7 @@ PyDoc_STRVAR(operator_doc,
This module exports a set of functions implemented in C corresponding\n\ This module exports a set of functions implemented in C corresponding\n\
to the intrinsic operators of Python. For example, operator.add(x, y)\n\ to the intrinsic operators of Python. For example, operator.add(x, y)\n\
is equivalent to the expression x+y. The function names are those\n\ is equivalent to the expression x+y. The function names are those\n\
used for special class methods; variants without leading and trailing\n\ used for special methods; variants without leading and trailing\n\
'__' are also provided for convenience."); '__' are also provided for convenience.");
#define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \
...@@ -277,26 +277,26 @@ spam2o(not_,__not__, "not_(a) -- Same as not a.") ...@@ -277,26 +277,26 @@ spam2o(not_,__not__, "not_(a) -- Same as not a.")
spam2(and_,__and__, "and_(a, b) -- Same as a & b.") spam2(and_,__and__, "and_(a, b) -- Same as a & b.")
spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.")
spam2(or_,__or__, "or_(a, b) -- Same as a | b.") spam2(or_,__or__, "or_(a, b) -- Same as a | b.")
spam2(iadd,__iadd__, "iadd(a, b) -- Same as a += b.") spam2(iadd,__iadd__, "a = iadd(a, b) -- Same as a += b.")
spam2(isub,__isub__, "isub(a, b) -- Same as a -= b.") spam2(isub,__isub__, "a = isub(a, b) -- Same as a -= b.")
spam2(imul,__imul__, "imul(a, b) -- Same as a *= b.") spam2(imul,__imul__, "a = imul(a, b) -- Same as a *= b.")
spam2(idiv,__idiv__, "idiv(a, b) -- Same as a /= b when __future__.division is not in effect.") spam2(idiv,__idiv__, "a = idiv(a, b) -- Same as a /= b when __future__.division is not in effect.")
spam2(ifloordiv,__ifloordiv__, "ifloordiv(a, b) -- Same as a //= b.") spam2(ifloordiv,__ifloordiv__, "a = ifloordiv(a, b) -- Same as a //= b.")
spam2(itruediv,__itruediv__, "itruediv(a, b) -- Same as a /= b when __future__.division is in effect.") spam2(itruediv,__itruediv__, "a = itruediv(a, b) -- Same as a /= b when __future__.division is in effect.")
spam2(imod,__imod__, "imod(a, b) -- Same as a %= b.") spam2(imod,__imod__, "a = imod(a, b) -- Same as a %= b.")
spam2(ilshift,__ilshift__, "ilshift(a, b) -- Same as a <<= b.") spam2(ilshift,__ilshift__, "a = ilshift(a, b) -- Same as a <<= b.")
spam2(irshift,__irshift__, "irshift(a, b) -- Same as a >>= b.") spam2(irshift,__irshift__, "a = irshift(a, b) -- Same as a >>= b.")
spam2(iand,__iand__, "iand(a, b) -- Same as a &= b.") spam2(iand,__iand__, "a = iand(a, b) -- Same as a &= b.")
spam2(ixor,__ixor__, "ixor(a, b) -- Same as a ^= b.") spam2(ixor,__ixor__, "a = ixor(a, b) -- Same as a ^= b.")
spam2(ior,__ior__, "ior(a, b) -- Same as a |= b.") spam2(ior,__ior__, "a = ior(a, b) -- Same as a |= b.")
spam2(concat,__concat__, spam2(concat,__concat__,
"concat(a, b) -- Same as a + b, for a and b sequences.") "concat(a, b) -- Same as a + b, for a and b sequences.")
spam2(repeat,__repeat__, spam2(repeat,__repeat__,
"repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.") "repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.")
spam2(iconcat,__iconcat__, spam2(iconcat,__iconcat__,
"iconcat(a, b) -- Same as a += b, for a and b sequences.") "a = iconcat(a, b) -- Same as a += b, for a and b sequences.")
spam2(irepeat,__irepeat__, spam2(irepeat,__irepeat__,
"irepeat(a, b) -- Same as a *= b, where a is a sequence, and b is an integer.") "a = irepeat(a, b) -- Same as a *= b, where a is a sequence, and b is an integer.")
spam2(getitem,__getitem__, spam2(getitem,__getitem__,
"getitem(a, b) -- Same as a[b].") "getitem(a, b) -- Same as a[b].")
spam2(setitem,__setitem__, spam2(setitem,__setitem__,
...@@ -304,7 +304,7 @@ spam2(setitem,__setitem__, ...@@ -304,7 +304,7 @@ spam2(setitem,__setitem__,
spam2(delitem,__delitem__, spam2(delitem,__delitem__,
"delitem(a, b) -- Same as del a[b].") "delitem(a, b) -- Same as del a[b].")
spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.") spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.")
spam2(ipow,__ipow__, "ipow(a, b) -- Same as a **= b.") spam2(ipow,__ipow__, "a = ipow(a, b) -- Same as a **= b.")
spam2(getslice,__getslice__, spam2(getslice,__getslice__,
"getslice(a, b, c) -- Same as a[b:c].") "getslice(a, b, c) -- Same as a[b:c].")
spam2(setslice,__setslice__, spam2(setslice,__setslice__,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment