[Patches] [ python-Patches-1004018 ] comparison of Decimal instance with None fails

SourceForge.net noreply at sourceforge.net
Fri Aug 6 07:16:55 CEST 2004


Patches item #1004018, was opened at 2004-08-05 11:37
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1004018&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Anthony Tuininga (atuining)
Assigned to: Nobody/Anonymous (nobody)
Summary: comparison of Decimal instance with None fails

Initial Comment:
attempting to perform a comparison of None with a
Decimal instance yields a type error:

TypeError: You can interact Decimal only with int, long
or Decimal data types.

Since all other types (that I am aware of anyway)
compare higher than None, it would make sense that the
new Decimal type would compare higher as well. Attached
is a patch that does just that. Comments welcome.

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

>Comment By: Tim Peters (tim_one)
Date: 2004-08-06 01:16

Message:
Logged In: YES 
user_id=31435

Sorry, I'm opposed to this.  Silently delivering a result when 
comparing to None has few intelligible use cases, but does 
hide errors quite effectively.  For this reason, it's generally 
true that the newer types in Python refuse non-equality 
comparisons with None (or with any other senselessly 
incompatible type).  For example,

>>> from datetime import date
>>> date.today() < None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: can't compare datetime.date to NoneType

>>> set([1, 2]) > None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: can only compare to a set
>>>

The new collections.deque type is an oddball in this respect, 
and should probably be "fixed":

>>> import collections
>>> collections.deque() > None
True
>>>

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1004018&group_id=5470


More information about the Patches mailing list