[Python-bugs-list] [ python-Bugs-497410 ] Builtin min()/max() semantic changed

noreply@sourceforge.net noreply@sourceforge.net
Fri, 28 Dec 2001 12:12:59 -0800


Bugs item #497410, was opened at 2001-12-28 11:41
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=497410&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Stuart Taylor (stu9480)
>Assigned to: Nobody/Anonymous (nobody)
Summary: Builtin min()/max() semantic changed

Initial Comment:
In python2.0

min(None, x) returns x
max(None, x) returns None

In python.2.2

min(None, x) returns None.
max(None, x) returns x.

Bug is old code will break if min() receives a 
None argument - as may be the case in loop
initialization.

Before:

Python 2.0 (#2, Oct 26 2000, 17:01:14) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)]
on linux2
Type "copyright", "credits" or "license" for more
information.
>>> min(None,4)
4

Now:

Python 2.2c1 (#2, Dec 16 2001, 19:12:17) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)]
on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> print min(None,4)
None
>>> 


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2001-12-28 12:12

Message:
Logged In: YES 
user_id=21627

This is not a bug. Python never guaranteed any specific
order of objects of different types; the documentation says

# Objects of different types, except different numeric
# types, never compare equal; such objects are ordered
# consistently but arbitrarily (so that sorting a 
# heterogeneous array yields a consistent result).
# Furthermore, some types (for example, file objects) 
# support only a degenerate notion of comparison where any 
# two objects of that type are unequal.  Again, such objects 
# are ordered arbitrarily but consistently.
It is not a bug if Python compares objects of different
types differently between versions, it is not even a bug if
it does so between different runs of the same Python
version. In Python 2.2, the implementation sorts None to be
smaller than any other object; that removes some of the
arbitrariness (but relying on this is still not portable).

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-28 12:01

Message:
Logged In: YES 
user_id=6380

This was changed in 2.1 already. The new behavior is better.
Code that relies on the relative ordering of objects of
different (non-numerical) types should be shot, anyway.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=497410&group_id=5470