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

Ethan Furman 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:
 return clock.factory()
 return None
Would need to make *flags change to the other *_clock functions.
> Have a quick glance at:
>> https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/clockutils.py

Thanks.
> 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.

Another +1.
~Ethan~


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /