[Python-Dev] an alternative to embedding policy in PEP 418 (was: PEP 418: Add monotonic clock)

Michael Urman murman at gmail.com
Fri Apr 6 13:31:45 CEST 2012


On Thu, Apr 5, 2012 at 21:57, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> I might have chosen to implement a 'None' return if I had designed
> open(), but I can't get too upset about raising an Exception as it
> actually does.

One fundamental difference is that there are many reasons one might
fail to open a file. It may not exist. It may not have permissions
allowing the request. It may be locked. If open() returned None, this
information would have to be retrievable through another function.
However since it returns an exception, that information is already
wrapped up in the exception object, should you choose to catch it, and
likely to be logged otherwise.

In the case of the clocks, I'm assuming the only reason you would fail
to get a clock is because it isn't provided by hardware and/or OS. You
don't have to worry about transient scenarios on multi-user systems
where another user has locked the clock. Thus the exception cannot
tell you anything more than None tells you. (Of course, if my
assumption is wrong, I'm not sure whether my reasoning still applies.)

-- 
Michael Urman


More information about the Python-Dev mailing list