Esempio 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
Esempio n. 2
0
def test_builtin_bound_method():
    assert inspect_callable("a".__getitem__) == Callable(str.__getitem__, self_obj="a")
Esempio 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'])
Esempio n. 4
0
def test_builtin_unbound_method():
    assert inspect_callable(str.__getitem__) == Callable(str.__getitem__)
Esempio n. 5
0
def test_static_method(cls):
    d = cls['base']()
    assert inspect_callable(d.staticmethod) == Callable(cls['base'].staticmethod)
Esempio 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)
Esempio n. 7
0
def test_function():
    assert inspect_callable(dummy) == Callable(dummy)
Esempio n. 8
0
def test_builtin_function():
    assert inspect_callable(isinstance) == Callable(isinstance)
Esempio 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))
Esempio 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))
Esempio 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")
Esempio n. 12
0
def test_builtin_unbound_method():
    ref_func = get_builtin_method_function(str.__getitem__)
    assert inspect_callable(str.__getitem__) == Callable(ref_func)
Esempio 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)
Esempio n. 14
0
def test_builtin_method_in_derived():
    s1 = mystr1("a")
    assert (inspect_callable(s1.__getitem__) == Callable(str.__getitem__, self_obj=s1))
Esempio n. 15
0
def test_unbound_method(cls):
    assert inspect_callable(cls['base'].method) == Callable(cls['base'].method)
Esempio n. 16
0
def test_builtin_method_overloaded_in_derived():
    s2 = mystr2("a")
    assert (inspect_callable(s2.__getitem__) == Callable(mystr2.__getitem__, self_obj=s2))
Esempio 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)
Esempio n. 18
0
def test_builtin_constructor():
    assert inspect_callable(str) == Callable(str, init=True)
Esempio n. 19
0
def test_call_method(cls):
    d = cls['base']()
    assert inspect_callable(d) == Callable(cls['base'].__call__, self_obj=d)
Esempio n. 20
0
def test_constructor(cls):
    assert inspect_callable(cls['base']) == Callable(cls['base'], init=True)
Esempio 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)