-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
doc: Mention the missing reflected operations #119931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 8 commits into
python:main
from
paulofreitas:rsub-arithmetic-operation
Jun 4, 2024
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
baa52ba
Mention `__rsub__` arithmetic operation
paulofreitas e99d7ad
Update Doc/reference/expressions.rst
serhiy-storchaka 8f666a0
Add the other reflected methods
paulofreitas b8cee56
Merge branch 'main' into rsub-arithmetic-operation
paulofreitas 646a125
Improved shifting operators and added `@` operators
paulofreitas 9b3bd75
Merge branch 'main' into rsub-arithmetic-operation
paulofreitas 89cc08e
Separate division and floor division
paulofreitas 3fc42e3
Merge branch 'main' into rsub-arithmetic-operation
paulofreitas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1211,7 +1211,8 @@ Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`. | |||
Raising a negative number to a fractional power results in a :class:`complex` | ||||
number. (In earlier versions it raised a :exc:`ValueError`.) | ||||
|
||||
This operation can be customized using the special :meth:`~object.__pow__` method. | ||||
This operation can be customized using the special :meth:`~object.__pow__` and | ||||
:meth:`~object.__rpow__` methods. | ||||
|
||||
.. _unary: | ||||
|
||||
|
@@ -1299,6 +1300,9 @@ This operation can be customized using the special :meth:`~object.__mul__` and | |||
The ``@`` (at) operator is intended to be used for matrix multiplication. No | ||||
builtin Python types implement this operator. | ||||
|
||||
This operation can be customized using the special :meth:`~object.__matmul__` and | ||||
:meth:`~object.__rmatmul__` methods. | ||||
|
||||
.. versionadded:: 3.5 | ||||
|
||||
.. index:: | ||||
|
@@ -1314,8 +1318,9 @@ integer; the result is that of mathematical division with the 'floor' function | |||
applied to the result. Division by zero raises the :exc:`ZeroDivisionError` | ||||
exception. | ||||
|
||||
This operation can be customized using the special :meth:`~object.__truediv__` and | ||||
:meth:`~object.__floordiv__` methods. | ||||
This operation can be customized using the special :meth:`~object.__truediv__`, | ||||
:meth:`~object.__rtruediv__`, :meth:`~object.__floordiv__` and | ||||
:meth:`~object.__rfloordiv__` methods. | ||||
|
||||
.. index:: | ||||
single: modulo | ||||
|
@@ -1340,7 +1345,8 @@ also overloaded by string objects to perform old-style string formatting (also | |||
known as interpolation). The syntax for string formatting is described in the | ||||
Python Library Reference, section :ref:`old-string-formatting`. | ||||
|
||||
The *modulo* operation can be customized using the special :meth:`~object.__mod__` method. | ||||
The *modulo* operation can be customized using the special :meth:`~object.__mod__` | ||||
and :meth:`~object.__rmod__` methods. | ||||
|
||||
The floor division operator, the modulo operator, and the :func:`divmod` | ||||
function are not defined for complex numbers. Instead, convert to a floating | ||||
|
@@ -1367,7 +1373,8 @@ This operation can be customized using the special :meth:`~object.__add__` and | |||
The ``-`` (subtraction) operator yields the difference of its arguments. The | ||||
numeric arguments are first converted to a common type. | ||||
|
||||
This operation can be customized using the special :meth:`~object.__sub__` method. | ||||
This operation can be customized using the special :meth:`~object.__sub__` and | ||||
:meth:`~object.__rsub__` methods. | ||||
|
||||
|
||||
.. _shifting: | ||||
|
@@ -1388,8 +1395,11 @@ The shifting operations have lower priority than the arithmetic operations: | |||
These operators accept integers as arguments. They shift the first argument to | ||||
the left or right by the number of bits given by the second argument. | ||||
|
||||
This operation can be customized using the special :meth:`~object.__lshift__` and | ||||
:meth:`~object.__rshift__` methods. | ||||
The left shift operation can be customized using the special :meth:`~object.__lshift__` | ||||
and :meth:`~object.__rlshift__` methods. | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would not be better to merge these two paragraphs?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure, merged it and did the same formatting for division and floor division operations. 👍 |
||||
The right shift operation can be customized using the special :meth:`~object.__rshift__` | ||||
and :meth:`~object.__rrshift__` methods. | ||||
|
||||
.. index:: pair: exception; ValueError | ||||
|
||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two different operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I was forgetting this one. 👍