[issue7989] Add pure Python implementation of datetime module to CPython
Alexander Belopolsky
report at bugs.python.org
Fri Jul 2 22:41:41 CEST 2010
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
> I am talking specifically about this kind of assert:
>
> assert 1 <= month <= 12, 'month must be in 1..12'
>
> I think it should be replaced with:
>
> if month < 1 or month > 12:
> raise ValueError('month must be in 1..12')
I reviewed the asserts. Value range checking asserts appear in non-public functions which are not called with out-of-range values by the module code. Therefore they can only be triggered if there is a bug in the future version of datetime.py. This is expressly what asserts are for.
There is another type of asserts that should be either removed or modified:
assert daysecondswhole == int(daysecondswhole) # can't overflow
Since int is long in 3.x, this assert does not check anything. We can replace this with
assert daysecondswhole.bit_length() <= 32
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7989>
_______________________________________
More information about the Python-bugs-list
mailing list