mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 12:16:58 +03:00
Added maybe_func utility
This commit is contained in:
parent
0531623ab3
commit
cb812958a2
|
@ -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']
|
||||
|
|
7
graphene/utils/maybe_func.py
Normal file
7
graphene/utils/maybe_func.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import inspect
|
||||
|
||||
|
||||
def maybe_func(f):
|
||||
if inspect.isfunction(f):
|
||||
return f()
|
||||
return f
|
9
graphene/utils/tests/test_maybe_func.py
Normal file
9
graphene/utils/tests/test_maybe_func.py
Normal 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
|
Loading…
Reference in New Issue
Block a user