Added maybe_func utility

This commit is contained in:
Syrus Akbary 2016-02-02 18:52:00 -08:00
parent 0531623ab3
commit cb812958a2
3 changed files with 18 additions and 1 deletions

View File

@ -1,11 +1,12 @@
from .str_converters import to_camel_case, to_snake_case
from .proxy_snake_dict import ProxySnakeDict
from .caching import cached_property, memoize
from .maybe_func import maybe_func
from .misc import enum_to_graphql_enum
from .resolve_only_args import resolve_only_args
from .lazylist import LazyList
__all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict',
'cached_property', 'memoize', 'enum_to_graphql_enum',
'cached_property', 'memoize', 'maybe_func', 'enum_to_graphql_enum',
'resolve_only_args', 'LazyList']

View File

@ -0,0 +1,7 @@
import inspect
def maybe_func(f):
if inspect.isfunction(f):
return f()
return f

View File

@ -0,0 +1,9 @@
from ..maybe_func import maybe_func
def maybe_func_function():
assert maybe_func(lambda: True) is True
def maybe_func_value():
assert maybe_func(True) is True