toil.lib.memoize

Module Contents

Functions

sync_memoize(f)

Like memoize, but guarantees that decorated function is only called once, even when multiple

parse_iso_utc(s)

Parses an ISO time with a hard-coded Z for zulu-time (UTC) at the end. Other timezones are

strict_bool(s)

Variant of bool() that only accepts two possible string values.

Attributes

memoize

Memoize a function result based on its parameters using this decorator.

MAT

MRT

toil.lib.memoize.memoize

Memoize a function result based on its parameters using this decorator.

For example, this can be used in place of lazy initialization. If the decorating function is invoked by multiple threads, the decorated function may be called more than once with the same arguments.

toil.lib.memoize.MAT
toil.lib.memoize.MRT
toil.lib.memoize.sync_memoize(f)[source]

Like memoize, but guarantees that decorated function is only called once, even when multiple threads are calling the decorating function with multiple parameters.

Parameters:

f (Callable[[MAT], MRT])

Return type:

Callable[[MAT], MRT]

toil.lib.memoize.parse_iso_utc(s)[source]

Parses an ISO time with a hard-coded Z for zulu-time (UTC) at the end. Other timezones are not supported. Returns a timezone-naive datetime object.

Parameters:

s (str) – The ISO-formatted time

Returns:

A timezone-naive datetime object

Return type:

datetime.datetime

>>> parse_iso_utc('2016-04-27T00:28:04.000Z')
datetime.datetime(2016, 4, 27, 0, 28, 4)
>>> parse_iso_utc('2016-04-27T00:28:04Z')
datetime.datetime(2016, 4, 27, 0, 28, 4)
>>> parse_iso_utc('2016-04-27T00:28:04X')
Traceback (most recent call last):
...
ValueError: Not a valid ISO datetime in UTC: 2016-04-27T00:28:04X
toil.lib.memoize.strict_bool(s)[source]

Variant of bool() that only accepts two possible string values.

Parameters:

s (str)

Return type:

bool