toil.lib.memoize

Attributes

memoize

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

MAT

MRT

Functions

sync_memoize(f)

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

parse_iso_utc(s)

Parses an RFC 3339 ISO 8601 time in the UTC timezone.

strict_bool(s)

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

Module Contents

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 (collections.abc.Callable[[MAT], MRT])

Return type:

collections.abc.Callable[[MAT], MRT]

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

Parses an RFC 3339 ISO 8601 time in the UTC timezone.

Other timezones are not supported. Returns a timezone-aware UTC datetime object.

Parameters:

s (str) – The ISO-formatted time

Returns:

A timezone-aware UTC datetime object

Raises:

ValueError – if the string is not in the correct format or is not in the UTC timezone.

Return type:

datetime.datetime

>>> parse_iso_utc('2016-04-27T00:28:04.000Z')
datetime.datetime(2016, 4, 27, 0, 28, 4, tzinfo=datetime.timezone.utc)
>>> parse_iso_utc('2016-04-27T00:28:04Z')
datetime.datetime(2016, 4, 27, 0, 28, 4, tzinfo=datetime.timezone.utc)
>>> 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