Exemplo n.º 1
0
def try_call(obj, args=(), kwds={}):
    # The only entry point for function calls.
    callable_ = inspect_callable(obj)

    if callable_.self_obj is not None:
        args = (callable_.self_obj,) + args
    obj = callable_.func_obj

    if not is_pure(obj):
        return False, None

    try:
        sig = get_signature(obj)
    except ValueError:
        return False, None

    try:
        sig.bind(*args, **kwds)
    except TypeError:
        # binding failed
        return False, None

    try:
        value = obj(*args, **kwds)
    except Exception:
        return False, None

    return True, value
Exemplo n.º 2
0
def test_builtin_bound_method():
    assert inspect_callable("a".__getitem__) == Callable(str.__getitem__, self_obj="a")
Exemplo n.º 3
0
def test_class_method_in_derived(cls):
    d = cls['derived']()
    classmethod_func = cls['base'].classmethod.__func__
    assert inspect_callable(d.classmethod) == Callable(classmethod_func, self_obj=cls['derived'])
Exemplo n.º 4
0
def test_builtin_unbound_method():
    assert inspect_callable(str.__getitem__) == Callable(str.__getitem__)
Exemplo n.º 5
0
def test_static_method(cls):
    d = cls['base']()
    assert inspect_callable(d.staticmethod) == Callable(cls['base'].staticmethod)
Exemplo n.º 6
0
def test_bound_method_in_derived(cls):
    d = cls['derived']()
    ref_func = get_method_function(cls['base'].method)
    assert inspect_callable(d.method) == Callable(ref_func, self_obj=d)
Exemplo n.º 7
0
def test_function():
    assert inspect_callable(dummy) == Callable(dummy)
Exemplo n.º 8
0
def test_builtin_function():
    assert inspect_callable(isinstance) == Callable(isinstance)
Exemplo n.º 9
0
def test_builtin_method_in_derived():
    s1 = mystr1("a")
    ref_func = get_builtin_method_function(str.__getitem__)
    assert (inspect_callable(s1.__getitem__) == Callable(ref_func, self_obj=s1))
Exemplo n.º 10
0
def test_builtin_method_overloaded_in_derived():
    s2 = mystr2("a")
    ref_func = get_method_function(mystr2.__getitem__)
    assert (inspect_callable(s2.__getitem__) == Callable(ref_func, self_obj=s2))
Exemplo n.º 11
0
def test_builtin_bound_method():
    ref_func = get_builtin_method_function(str.__getitem__)
    assert inspect_callable("a".__getitem__) == Callable(ref_func, self_obj="a")
Exemplo n.º 12
0
def test_builtin_unbound_method():
    ref_func = get_builtin_method_function(str.__getitem__)
    assert inspect_callable(str.__getitem__) == Callable(ref_func)
Exemplo n.º 13
0
def test_call_method(cls):
    d = cls['base']()
    ref_func = get_method_function(cls['base'].__call__)
    assert inspect_callable(d) == Callable(ref_func, self_obj=d)
Exemplo n.º 14
0
def test_builtin_method_in_derived():
    s1 = mystr1("a")
    assert (inspect_callable(s1.__getitem__) == Callable(str.__getitem__, self_obj=s1))
Exemplo n.º 15
0
def test_unbound_method(cls):
    assert inspect_callable(cls['base'].method) == Callable(cls['base'].method)
Exemplo n.º 16
0
def test_builtin_method_overloaded_in_derived():
    s2 = mystr2("a")
    assert (inspect_callable(s2.__getitem__) == Callable(mystr2.__getitem__, self_obj=s2))
Exemplo n.º 17
0
def test_bound_method_in_derived(cls):
    d = cls['derived']()
    assert inspect_callable(d.method) == Callable(cls['base'].method, self_obj=d)
Exemplo n.º 18
0
def test_builtin_constructor():
    assert inspect_callable(str) == Callable(str, init=True)
Exemplo n.º 19
0
def test_call_method(cls):
    d = cls['base']()
    assert inspect_callable(d) == Callable(cls['base'].__call__, self_obj=d)
Exemplo n.º 20
0
def test_constructor(cls):
    assert inspect_callable(cls['base']) == Callable(cls['base'], init=True)
Exemplo n.º 21
0
def test_unbound_method(cls):
    ref_func = get_method_function(cls['base'].method)
    assert inspect_callable(cls['base'].method) == Callable(ref_func)