Message377847
For rich comparisons, a proper explanation is given in the rich comparison entry in the datamodel section ( #41910)
"A rich comparison method may return the singleton NotImplemented if it does not implement the operation for a given pair of arguments. By convention, False and 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 if statement), Python will call bool() on the value to determine if the result is true or false."
bool(x) calls x.__bool__ and requires that the latter return False or True.
As for the other two comparisons, x is y always returns False or True for a proper implementation because int == int always does. If y.__contains__(x) does not raise, x in y returns bool(y.__contains__(x)), clamping aberrant implementations of __contains__.
A replacement text might be
"Comparisons normally yield boolean values: True or False. But rich comparisons not in a Boolean context may yield anything."
Possibly link 'rich comparisons' to the datamodel section. |
|
Date |
User |
Action |
Args |
2020-10-03 01:43:58 | terry.reedy | set | recipients:
+ terry.reedy, brett.cannon |
2020-10-03 01:43:58 | terry.reedy | set | messageid: <1601689438.59.0.230854251145.issue41911@roundup.psfhosted.org> |
2020-10-03 01:43:58 | terry.reedy | link | issue41911 messages |
2020-10-03 01:43:58 | terry.reedy | create | |
|