Skip to content

Commit c48d834

Browse files
committed
Issue python#1717: documentation fixes related to the cmp removal.
1 parent c008a17 commit c48d834

6 files changed

Lines changed: 45 additions & 36 deletions

File tree

Doc/includes/sqlite3/collation_reverse.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import sqlite3
22

33
def collate_reverse(string1, string2):
4-
return -cmp(string1, string2)
4+
if string1 == string2:
5+
return 0
6+
elif string1 < string2:
7+
return 1
8+
else:
9+
return -1
510

611
con = sqlite3.connect(":memory:")
712
con.create_collation("reverse", collate_reverse)

Doc/library/locale.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ The :mod:`locale` module defines the following exception and functions:
225225

226226
.. function:: strxfrm(string)
227227

228-
.. index:: builtin: cmp
229-
230-
Transforms a string to one that can be used for the built-in function
231-
:func:`cmp`, and still returns locale-aware results. This function can be used
232-
when the same string is compared repeatedly, e.g. when collating a sequence of
233-
strings.
228+
Transforms a string to one that can be used in locale-aware
229+
comparisons. For example, ``strxfrm(s1) < strxfrm(s2)`` is
230+
equivalent to ``strcoll(s1, s2) < 0``. This function can be used
231+
when the same string is compared repeatedly, e.g. when collating a
232+
sequence of strings.
234233

235234

236235
.. function:: format(format, val[, grouping[, monetary]])

Doc/library/operator.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ the rich comparison operators they support:
4343
equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
4444
b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
4545
``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
46-
>= b``. Note that unlike the built-in :func:`cmp`, these functions can
47-
return any value, which may or may not be interpretable as a Boolean value.
48-
See :ref:`comparisons` for more information about rich comparisons.
46+
>= b``. Note that these functions can return any value, which may
47+
or may not be interpretable as a Boolean value. See
48+
:ref:`comparisons` for more information about rich comparisons.
4949

5050

5151
The logical operations are also generally applicable to all objects, and support

Doc/library/unittest.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,9 @@ will create a test suite that will run ``WidgetTestCase.testDefaultSize()`` and
327327
``WidgetTestCase.testResize``. :class:`TestLoader` uses the ``'test'`` method
328328
name prefix to identify test methods automatically.
329329

330-
Note that the order in which the various test cases will be run is determined by
331-
sorting the test function names with the built-in :func:`cmp` function.
330+
Note that the order in which the various test cases will be run is
331+
determined by sorting the test function names with respect to the
332+
built-in ordering for strings.
332333

333334
Often it is desirable to group suites of test cases together, so as to run tests
334335
for the whole system at once. This is easy, since :class:`TestSuite` instances
@@ -921,9 +922,13 @@ subclassing or assignment on an instance:
921922
.. attribute:: TestLoader.sortTestMethodsUsing
922923

923924
Function to be used to compare method names when sorting them in
924-
:meth:`getTestCaseNames` and all the :meth:`loadTestsFrom\*` methods. The
925-
default value is the built-in :func:`cmp` function; the attribute can also be
926-
set to :const:`None` to disable the sort.
925+
:meth:`getTestCaseNames` and all the :meth:`loadTestsFrom\*`
926+
methods. This should be a function that takes two arguments
927+
``self`` and ``other``, and returns ``-1`` if ``self`` precedes
928+
``other`` in the desired ordering, ``1`` if ``other`` precedes
929+
``self``, and ``0`` if ``self`` and ``other`` are equal. The
930+
default ordering is the built-in ordering for strings. This
931+
attribute can also be set to :const:`None` to disable the sort.
927932

928933

929934
.. attribute:: TestLoader.suiteClass

Doc/reference/expressions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,8 @@ Comparison of objects of the same type depends on the type:
10221022
length.
10231023

10241024
If not equal, the sequences are ordered the same as their first differing
1025-
elements. For example, ``cmp([1,2,x], [1,2,y])`` returns the same as
1026-
``cmp(x,y)``. If the corresponding element does not exist, the shorter
1025+
elements. For example, ``[1,2,x] <= [1,2,y]`` has the same value as
1026+
``x <= y``. If the corresponding element does not exist, the shorter
10271027
sequence is ordered first (for example, ``[1,2] < [1,2,3]``).
10281028

10291029
* Mappings (dictionaries) compare equal if and only if their sorted ``(key,

Doc/tutorial/modules.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,25 @@ want a list of those, they are defined in the standard module
317317
>>> dir(builtins)
318318

319319
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'Buffer
320-
Error', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Excep
321-
tion', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError
322-
', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError',
323-
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImp
324-
lemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecatio
325-
nWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StopIteration',
326-
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True',
327-
'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', '
328-
UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueE
329-
rror', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__'
330-
, '__import__', '__name__', 'abs', 'all', 'any', 'basestring', 'bin', 'bool', 'b
331-
uffer', 'bytes', 'chr', 'chr8', 'classmethod', 'cmp', 'compile', 'complex', 'cop
332-
yright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'ex
333-
ec', 'exit', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'h
334-
ash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', '
335-
len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'o
336-
bject', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr
337-
', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'st
338-
r', 'str8', 'sum', 'super', 'trunc', 'tuple', 'type', 'vars', 'zip']
320+
Error', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'Environme
321+
ntError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'Generato
322+
rExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexErr
323+
or', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError',
324+
'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'P
325+
endingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', '
326+
StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'Ta
327+
bError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'Unicod
328+
eEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserW
329+
arning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__deb
330+
ug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any',
331+
'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'chr', 'classmethod', 'compile', '
332+
complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate
333+
', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr',
334+
'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance',
335+
'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memory
336+
view', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property'
337+
, 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sort
338+
ed', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
339339

340340
.. _tut-packages:
341341

0 commit comments

Comments
 (0)