[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


http://bugs.python.org/review/12067/diff/19802/Doc/reference/expressions.rst
File Doc/reference/expressions.rst (right):

http://bugs.python.org/review/12067/diff/19802/Doc/reference/expressions.rst#newcode1154
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
interoperable.

>>> chr(0xff) == unichr(0xff)
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert
both arguments to Unicode - interpreting them as being unequal
False
>>> 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.

http://bugs.python.org/review/12067/diff/19802/Doc/reference/expressions.rst#newcode1174
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.

http://bugs.python.org/review/12067/diff/19802/Doc/reference/expressions.rst#newcode1197
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
equality.

http://bugs.python.org/review/12067/


More information about the docs mailing list