[Python-Dev] [Python-checkins] cpython: Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Stefan Krah
stefan at bytereef.org
Fri May 4 11:33:49 CEST 2012
Larry Hastings <larry at hastings.org> wrote:
> 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?
I had the same question a while ago, and IIRC Raymond said that the convention
is to raise a TypeError if a combination of arguments cannot be handled by a
function.
In OCaml this would be quite natural:
$ ocaml
Objective Caml version 3.12.0
# type kwargs = TIMES | NS;;
type kwargs = TIMES | NS
let utime args =
match args with
| (_, TIMES) -> "Got times"
| (_, NS) -> "Got NS";;
val utime : 'a * kwargs -> string = <fun>
# utime ("/etc/passwd", TIMES);;
- : string = "Got times"
# utime ("/etc/passwd", NS);;
- : string = "Got NS"
# utime ("/etc/passwd", TIMES, NS);;
Error: This expression has type string * kwargs * kwargs
but an expression was expected of type 'a * kwargs
In Python it makes sense if (for the purpose of raising an error) one assumes
that {"times":(0, 0)}, {"ns":(0, 0)} and {"times":(0, 0), "ns":(0, 0)} have
different types.
Stefan Krah
More information about the Python-Dev
mailing list