[Python-Dev] total ordering.
Vladimir 'Yu' Stepanov
vys at renet.ru
Tue May 16 18:11:08 CEST 2006
Guido van Rossum wrote:
> On 5/11/06, Vladimir 'Yu' Stepanov <vys at renet.ru> wrote:
>> If for Python-3000 similar it will be shown concerning types
>> str(), int(), complex() and so on, and the type of exceptions
>> will strongly vary, it will make problematic redefinition of
>> behavior of function of sorting.
> Not really. We'll just document that sort() should only be used on a
> list of objects that implement a total ordering. The behavior
> otherwise will simply be undefined; it will raise whatever exception
> is first raised by an unsupported comparison (most likely TypeError).
> In practice this won't be a problem.
In my opinion for functions of comparisons there is no additional
kind of exceptions. If made action is not operation of reduction of
type more often exception TypeError means a mistake of programming.
At creation of exception, characteristic only for comparison, it
is possible to involve methods `.__r(eq|ne|le|lt|ge|gt|cmp)__()'
not being afraid to hide a mistake of programming TypeError (sorry
for a tautology).
It will be possible it conveniently to use as exception of
management by a stream, for indication of necessity to involve
`.__r(eq|ne|le|lt|ge|gt|cmp)__()' a method. This kind of a class
can carry out function, similarly to StopIteration for `.next()'.
In case of unsuccessful comparison the user has an opportunity in
function `cmp' a method .sort() simple image to define the
behaviour necessary to it, including an opportunity of sorting of
At present time similar function is carried out with exception
NotImplemented. This exception is generated in a number of
mathematical operations. For this reason I ask to consider an
opportunity of creation of a new class.
More information about the Python-Dev