Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c54173c2
Commit
c54173c2
authored
Jun 14, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1153163: describe __add__ vs __radd__ behavior when adding
objects of same type/of subclasses of the other.
parent
bcae6222
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+19
-4
No files found.
Doc/ref/ref3.tex
View file @
c54173c2
...
...
@@ -1918,13 +1918,28 @@ called to implement the binary arithmetic operations (\code{+},
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<<
}
,
\code
{
>>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
) with reflected
(swapped) operands. These functions are only called if the left
operand does not support the corresponding operation. For instance,
to evaluate the expression
\var
{
x
}
\code
{
-
}
\var
{
y
}
, where
\var
{
y
}
is an
instance of a class that has an
\method
{__
rsub
__
()
}
method,
\code
{
\var
{
y
}
.
__
rsub
__
(
\var
{
x
}
)
}
is called. Note that ternary
operand does not support the corresponding operation and the
operands are of different types.
\footnote
{
For operands of the same type, it is assumed that if the
non-reflected method (such as
\method
{__
add
__
()
}
) fails the
operation is not supported, which is why the reflected method
is not called.
}
For instance, to evaluate the expression
\var
{
x
}
\code
{
-
}
\var
{
y
}
,
where
\var
{
y
}
is an instance of a class that has an
\method
{__
rsub
__
()
}
method,
\code
{
\var
{
y
}
.
__
rsub
__
(
\var
{
x
}
)
}
is called if
\code
{
\var
{
x
}
.
__
sub
__
(
\var
{
y
}
)
}
returns
\var
{
NotImplemented
}
.
Note that ternary
\function
{
pow()
}
\bifuncindex
{
pow
}
will not try calling
\method
{__
rpow
__
()
}
(the coercion rules would become too
complicated).
\note
{
If the right operand's type is a subclass of the left operand's
type and that subclass provides the reflected method for the
operation, this method will be called before the right operand's
non-reflected method. This behavior allows subclasses to
override their ancestors' operations.
}
\end{methoddesc}
\begin{methoddesc}
[numeric object]
{__
iadd
__}{
self, other
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment