[Python-Dev] [Python-checkins] cpython: Issue #14127: Add ns= parameter to utime, futimes, and lutimes.

Larry Hastings larry at hastings.org
Fri May 4 08:04:16 CEST 2012


On 05/03/2012 10:07 PM, Benjamin Peterson wrote:
>> +    if (times&&  ns) {
>> +        PyErr_Format(PyExc_RuntimeError,
> Why not a ValueError or TypeError?

Well it's certainly not a TypeError.  The 3.2 documentation defines 
TypeError as:

    Raised when an operation or function is applied to an object of
    inappropriate type. The associated value is a string giving details
    about the type mismatch.

If someone called os.utime with both times and ns, and the values of 
each would have been legal if they'd been passed in in isolation, what 
would be the type mismatch?


ValueError seems like a stretch.  The 3.2 documentation defines 
ValueError as

    Raised when a built-in operation or function receives an argument
    that has the right type but an inappropriate value, and the
    situation is not described by a more precise exception such as
    IndexError.

To me this describes a specific class of errors where a single value is 
invalid in isolation, like an overly-long string for a path on Windows, 
or a negative integer for some integer value that must always be 0 or 
greater.  The error with utime is a different sort of error; you are 
passing in two presumably legal values, but the function requires that 
you pass in at most one.

The only way I can see ValueError as being the right choice is from the 
awkward perspective of "if you passed in times, then the only valid 
value for ns is None" (or vice-versa).

Are there existing APIs that use ValueError for just this sort of 
situation?  I dimly recall there being something like this but I can't 
recall it.

Is using RuntimeError some sort of Pythonic faux pas?


>> +    if (times&&  (times != Py_None)) {
> Conditions in parenthesis like this is not style.

Can you point me to where this is described in PEP 7?  I can't find it.


>> +        return (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0),
>> +&(ua->atime_s),&(ua->atime_ns)) != -1)
>> +&&  (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1),
> Put&&  on previous line like Python.

Okay.

Since I have questions regarding two of your three suggested changes, 
I'll hold off on making any changes until the dust settles a little.


Finally, I appreciate the feedback, but... why post it to python-dev?  
You could have sent me private email, or posted to the issue (#14127), 
the latter of which would have enabled using rich chocolaty Rietveld.  
I've seen a bunch of comments on checkins posted here and it all leaves 
me scratching my head.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120503/36cd9bf4/attachment.html>


More information about the Python-Dev mailing list