[Python-Dev] Boundary checks on arguments to time.strftime()

Aahz aahz at pythoncraft.com
Mon Feb 23 10:51:04 EST 2004


On Sun, Feb 22, 2004, Brett C. wrote:
>
> I would like to raise a ValueError if the argument is out of range. 
> Problem is that this will break code.  

+1

After all, code is already breaking.

> I could just force all negative values to all values outside the
> proper bounds to a reasonable value, but that seems to go against the
> path of least surprise.  That is question 1.

-1

> Question 2 is what to really check.  This really is only a concern for 
> month and day of the week since everything else is just a number and 
> doesn't have some name representation.  I could check all 9 values, 
> though, or just these two.

+0

> Question 3 is whether to extend this to time.asctime() .  I have talked 
> to Tim about this and his thoughts are to just deal with time.strftime() 
> and leave everything else alone.  That's fine with me, but there is the 
> same possibility of having problems with asctime().  But then again, 
> checking value for asctime() would potentially break even more code.

+1

Behavior of similar functions should be as similar as possible.  While I
see Raymond's point about this being a less likely bug to hit, why not
make the fix now while a pair of eyeballs that knows the code is already
looking?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Do not taunt happy fun for loops. Do not change lists you are looping over."
--Remco Gerlich, comp.lang.python



More information about the Python-Dev mailing list