[docs] Doc: remove errors about mixed-type comparisons. (issue 12067)

storchaka+cpython at gmail.com storchaka+cpython at gmail.com
Sat Jan 21 07:03:53 EST 2017

File Doc/reference/expressions.rst (right):

Doc/reference/expressions.rst:1154: 8-bit strings are fully
interoperable in this behavior. [#]_
This description is misleading. Unicode and 8-bit strings are not fully

>>> chr(0xff) == unichr(0xff)
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert
both arguments to Unicode - interpreting them as being unequal
>>> chr(0xff) < unichr(0xff)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0:
ordinal not in range(128)

When compare str and unicode, the str operand is converted to Unicode.
If the conversion is failed, values are traited as non-equal.

Doc/reference/expressions.rst:1174: - For two collections to compare
equal, they must be of the same type, have
> they must be of the same type

Subclasses are comparable with base class or other subclasses of the
same base class.

Doc/reference/expressions.rst:1197: User-defined classes that customize
their comparison behavior should follow
Would it be worth to document when custom comparison methods should
return NotImplemented?

The hash of hashable user defined classes should be consistent with the


More information about the docs mailing list