Re: [Python-Dev] Keep default comparisons - or add a second set?
Noam Raphael wrote:
I don't think that every type that supports equality comparison should support order comparison. I think that if there's no meaningful comparison (whether equality or order), an exception should be raised.
Just to keep myself sane... def date_range(start=None, end=None): if start == None: start = datetime.date.today() if end == None: end = datetime.date.today() return end - start Are you saying the "if" statements will raise TypeError if start or end are dates? That would be a sad day for Python. Perhaps you're saying that there is a "meaningful comparison" between None and anything else, but please clarify if so. Robert Brewer System Architect Amor Ministries fumanchu@amor.org
On 12/29/05, Robert Brewer <fumanchu@amor.org> wrote:
Just to keep myself sane...
def date_range(start=None, end=None): if start == None: start = datetime.date.today() if end == None: end = datetime.date.today() return end - start
Are you saying the "if" statements will raise TypeError if start or end are dates? That would be a sad day for Python. Perhaps you're saying that there is a "meaningful comparison" between None and anything else, but please clarify if so.
Yes, I'm suggesting that they will raise a TypeError. Your example shows that the change is not compatible with a lot of existing Python code, which means that it's a Python 3000 thing. The following code will continue to work: def date_range(start=None, end=None): if start is None: start = datetime.date.today() if end is None: end = datetime.date.today() return end - start Using "is None" instead of "== None" is considered a better style even now. Noam
On 12/28/05, Robert Brewer <fumanchu@amor.org> wrote:
Noam Raphael wrote:
I don't think that every type that supports equality comparison should support order comparison. I think that if there's no meaningful comparison (whether equality or order), an exception should be raised.
Just to keep myself sane...
def date_range(start=None, end=None): if start == None: start = datetime.date.today() if end == None: end = datetime.date.today() return end - start
Are you saying the "if" statements will raise TypeError if start or end are dates? That would be a sad day for Python. Perhaps you're saying that there is a "meaningful comparison" between None and anything else, but please clarify if so.
Not to worry. My plans for Py3K are to ditch </<=/>/>= unless explicitly defined, but to define == and != on all objects -- if not explicitly defined, == will be false and != will be true. Types can still override == and != to raise exceptions if they really want to guard against certain comparisons; but equality is too important an operation to drop. It should still be possible to use dicts with mixed-type keys! -- --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (3)
-
Guido van Rossum -
Noam Raphael -
Robert Brewer