コード例 #1
0
ファイル: asynq_checker.py プロジェクト: ymichael/pyanalyze
def is_impure_async_fn(value):
    """Returns whether the given Value is an impure async call.

    This can be used to detect places where async functions are called synchronously.

    """
    if isinstance(value, KnownValue):
        return asynq.is_async_fn(value.val) and not asynq.is_pure_async_fn(value.val)
    elif isinstance(value, UnboundMethodValue):
        method = value.get_method()
        if method is None:
            return False
        return asynq.is_async_fn(method) and not asynq.is_pure_async_fn(method)
    return False
コード例 #2
0
ファイル: test_decorators.py プロジェクト: nhajare/asynq
def test_is_pure_async_fn():
    assert is_pure_async_fn(lazy_fn)
    assert not is_pure_async_fn(test_lazy)
    assert not is_pure_async_fn(async_fn)
    assert is_pure_async_fn(pure_async_fn)
    assert not is_pure_async_fn(DisallowSetting())
    assert is_pure_async_fn(MyClass.get_cls)
    assert not is_pure_async_fn(MyClass.get_cls_ac)
    assert not is_pure_async_fn(AsyncDecorator)
コード例 #3
0
ファイル: test_decorators.py プロジェクト: nhajare/asynq
def test_make_async_decorator():
    assert_eq(18, square(3))
    assert_eq(18, MyClass.square(3))
    assert_eq(18, square.asynq(3).value())
    assert_eq(18, MyClass.square.asynq(3).value())

    assert not is_pure_async_fn(square)
    assert_eq("@double_return_value()", square.name())
コード例 #4
0
ファイル: test_decorators.py プロジェクト: nhajare/asynq
def test_get_async_fn():
    assert_eq(async_fn.asynq, get_async_fn(async_fn))
    assert_eq(lazy_fn, get_async_fn(lazy_fn))
    assert_is(None, get_async_fn(sync_fn))

    wrapper = get_async_fn(sync_fn, wrap_if_none=True)
    assert is_pure_async_fn(wrapper)
    result = wrapper()
    assert_is_instance(result, ConstFuture)
    assert_eq("sync_fn", result.value())