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
57d191fe
Commit
57d191fe
authored
Mar 06, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1602128: clarify that richcmp methods can return NotImplemented
and should return True or False otherwise.
parent
6fc1697c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+9
-7
No files found.
Doc/ref/ref3.tex
View file @
57d191fe
...
...
@@ -1282,10 +1282,14 @@ follows:
\code
{
\var
{
x
}
.
__
ne
__
(
\var
{
y
}
)
}
,
\code
{
\var
{
x
}
>
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
gt
__
(
\var
{
y
}
)
}
, and
\code
{
\var
{
x
}
>=
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
ge
__
(
\var
{
y
}
)
}
.
These methods can return any value, but if the comparison operator is
used in a Boolean context, the return value should be interpretable as
a Boolean value, else a
\exception
{
TypeError
}
will be raised.
By convention,
\code
{
False
}
is used for false and
\code
{
True
}
for true.
A rich comparison method may return the singleton
\code
{
NotImplemented
}
if it
does not implement the operation for a given pair of arguments.
By convention,
\code
{
False
}
and
\code
{
True
}
are returned for a successful
comparison. However, these methods can return any value, so if the
comparison operator is used in a Boolean context (e.g., in the condition
of an
\code
{
if
}
statement), Python will call
\function
{
bool()
}
on the
value to determine if the result is true or false.
There are no implied relationships among the comparison operators.
The truth of
\code
{
\var
{
x
}
==
\var
{
y
}}
does not imply that
\code
{
\var
{
x
}
!=
\var
{
y
}}
...
...
@@ -1299,9 +1303,7 @@ the right argument does); rather, \method{__lt__()} and
\method
{__
ge
__
()
}
are each other's reflection, and
\method
{__
eq
__
()
}
and
\method
{__
ne
__
()
}
are their own reflection.
Arguments to rich comparison methods are never coerced. A rich
comparison method may return
\code
{
NotImplemented
}
if it does not
implement the operation for a given pair of arguments.
Arguments to rich comparison methods are never coerced.
\end{methoddesc}
\begin{methoddesc}
[object]
{__
cmp
__}{
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