[Python-Dev] an alternative to embedding policy in PEP 418 (was: PEP 418: Add monotonic clock)
ethan at stoneleaf.us
Wed Apr 4 00:08:29 CEST 2012
Cameron Simpson wrote:
> get_clock already has two arguments - you can optionally hand it a clock
> list - that's used by monotonic_clock() and hires_clock().
def get_clock(*flags, *, clocklist=None):
''' Return a Clock based on the supplied `flags`.
The returned clock shall have all the requested flags.
If no clock matches, return None.
wanted = 0
for flag in flags:
wanted |= flag
if clocklist is None:
clocklist = ALL_CLOCKS
for clock in clocklist:
if clock.flags & wanted == wanted:
Would need to make *flags change to the other *_clock functions.
> Have a quick glance at:
> The return of None is very deliberate. I _want_ user specified fallback
> to be concise and easy. The example:
> clock = get_clock(MONOTONIC|HIRES) or get_clock(MONOTONIC)
Which would become:
clock = get_clock(MONOTONIC, HIGHRES) or get_clock(MONOTONIC)
+1 to returning None
> Exceptions are all very well when there is just one thing to do: parse
> this or fail, divide this by that or fail. If fact they're the very
> image of "do this one thing or FAIL". They are not such a good match for do
> this thing or that thing or this other thing.
> When you want a simple linear cascade of choices, Python's short circuiting
> "or" operator is a very useful thing. Having an obsession with exceptions is
> IMO unhealthy.
More information about the Python-Dev