[issue7989] Add pure Python implementation of datetime module to CPython

Antoine Pitrou report at bugs.python.org
Thu Jul 1 18:09:06 CEST 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

> In any case, my threshold for moving this forward is for someone to
> review the code in sandbox.

Ok some comments:

- I find the _cmp() and __cmp() indirection poor style in 3.x, especially when you simply end up comparing self._getstate() and other._getstate() (it is also suboptimal because it can do more comparisons than needed)

- Shouldn't __eq__ and friends return NotImplemented if the other type mismatches, to give the other class a chance to implement its own comparison method? that's what built-in types do, as least
(this would also make _cmperror useless)

- Using assert to check arguments is bad. Either there's a risk of bad input, and you should raise a proper error (for example ValueError), or there is none and the assert can be left out.

- Starting _DAYS_IN_MONTH with a None element and then iterating over _DAYS_IN_MONTH[1:] looks quirky

- Using double-underscored names such as __day is generally discouraged, simple-underscored names (e.g. _day) should be preferred

- Some comments about "CPython compatibility" should be removed

- Some other comments should be reconsidered or removed, such as "# XXX The following should only be used as keyword args" or "XXX Buggy in 2.2.2"

- Some things are inconsistent: date uses bytes for pickle support, time uses str for the same purpose

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7989>
_______________________________________


More information about the Python-bugs-list mailing list