[Patches] [ python-Patches-1004018 ] comparison of Decimal instance
with None fails
SourceForge.net
noreply at sourceforge.net
Fri Aug 6 15:46:29 CEST 2004
Patches item #1004018, was opened at 2004-08-05 09:37
Message generated for change (Comment added) made by atuining
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: Anthony Tuininga (atuining)
Date: 2004-08-06 07:46
Message:
Logged In: YES
user_id=619560
Ah, very interesting. I hadn't tried datetime data yet and
that one will also be an issue for us. Let me give you a
little background so you know why I am suggesting this. We
are acquiring data from a database where floating point
numbers are returned as decimal instances and date as
datetime instances. Some of this data may be null which in
DB API parlance means a None instance. Its quite annoying to
have a list of data values, some of which are null and have
a TypeError exception raised. I'm not sure how familiar you
are with the DB API and databases in general but this
behavior makes such types unusable -- which is unfortunate.
We will have to subclass or write our own "Value" class that
has the behavior we want. Do you have any further comments
about the concept of "null" with respect to databases? Or do
your existing comments still stand?
The other question I would leave you with is: comparing with
an empty set is quite possible, but how about an "empty"
decimal or "empty" datetime instance?
Thanks for the response thus far -- even if it wasn't what I
wanted. :-)
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2004-08-05 23: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