[Python-Dev] Re: dateutil (original) (raw)

Paul Moore pf_moore at yahoo.co.uk
Mon Mar 15 18:04:06 EST 2004


Greg Ewing <greg at cosc.canterbury.ac.nz> writes:

Gustavo Niemeyer <niemeyer at conectiva.com>:

(just as examples)

d + relativedelta(day=1) d + relativedelta(day=31) Sorry, but the more I see of this usage the worse it looks. Here you're effectively using '+' as an assignment operator. To me, that's a gross abuse of the Python language.

You're right, that's a particularly nasty example. More "normal" usages feel far better, because they do feel like additions to me. You could improve these cases by renaming relativedelta as something like duration_until(), but really that's only hiding the issue.

Nevertheless, I do like the functionality. And the conciseness.

In some ways, i'd rather spell these examples as

d.replace(day=1)
d.replace(day=-1)

The former works, but the latter doesn't. One problem is that negative arguments only really make any sense for the day argument.

Hmm, thinking about it, how will relativedelta objects get used? Most of the time, I'd be adding relativedelta "constants". So maybe using a simple function would be better:

dateutil.adjust(d, day=1)
dateutil.adjust(d, day=-1)
dateutil.adjust(d, day=1, months=+1, days=-1)

Does this look any better?

Paul

This signature intentionally left blank



More information about the Python-Dev mailing list