How to use the klepto.signature function in klepto

To help you get started, we’ve selected a few klepto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_signature():
    s = signature(bar)
    assert s == (('x', 'y', 'z', 'a', 'b'), {'a': 1, 'b': 2}, 'args', '')

    # a partial with a 'fixed' x, thus x is 'unsettable' as a keyword
    p = partial(bar, 0)
    s = signature(p)
    assert s == (('y', 'z', 'a', 'b'), {'a': 1, '!x': 0, 'b': 2}, 'args', '')
    '''
    >>> p(0,1)  
        4
    >>> p(0,1,2,3,4,5)
        6
    '''
    # a partial where y is 'unsettable' as a positional argument
    p = partial(bar, y=10)
    s = signature(p)
    assert s == (('x', '!y', 'z', 'a', 'b'), {'a': 1, 'y': 10, 'b': 2}, 'args', '')
github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_special():
    p = partial(add, 0,x=0)
    p2 = partial(add, z=0)
    p3 = partial(add, 0)

    
    if IS_PYPY: # builtins in PYPY are python functions
        assert signature(pow, safe=True) == (('base', 'exponent', 'modulus'), {'modulus': None}, '', '')
    else:
        assert signature(pow, safe=True) == (None, None, None, None)
    assert signature(p, safe=True) == (None, None, None, None)
    assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '')
    assert signature(p3, safe=True) == (('y',), {'!x': 0}, '', '')
    if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow
        assert isvalid(pow, 0,1) == True
        assert isvalid(pow, 0) == False
        assert isvalid(pow) == False
    else: # python >= 3.5 bug in ArgSpec for pow, so use min
        assert isvalid(min, 0,1) == True
        assert isvalid(min, 0) == False
        assert isvalid(min) == False
    assert isvalid(p, 0,1) == False
    assert isvalid(p, 0) == False
    assert isvalid(p) == False
    assert isvalid(p2, 0,1) == False
    assert isvalid(p2, 0) == False
    assert isvalid(p2) == False
    assert isvalid(p3, 0,1) == False
github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_signature():
    s = signature(bar)
    assert s == (('x', 'y', 'z', 'a', 'b'), {'a': 1, 'b': 2}, 'args', '')

    # a partial with a 'fixed' x, thus x is 'unsettable' as a keyword
    p = partial(bar, 0)
    s = signature(p)
    assert s == (('y', 'z', 'a', 'b'), {'a': 1, '!x': 0, 'b': 2}, 'args', '')
    '''
    >>> p(0,1)  
        4
    >>> p(0,1,2,3,4,5)
        6
    '''
    # a partial where y is 'unsettable' as a positional argument
    p = partial(bar, y=10)
    s = signature(p)
    assert s == (('x', '!y', 'z', 'a', 'b'), {'a': 1, 'y': 10, 'b': 2}, 'args', '')
    '''
    >>> p(0,1,2)
github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_special():
    p = partial(add, 0,x=0)
    p2 = partial(add, z=0)
    p3 = partial(add, 0)

    
    if IS_PYPY: # builtins in PYPY are python functions
        assert signature(pow, safe=True) == (('base', 'exponent', 'modulus'), {'modulus': None}, '', '')
    else:
        assert signature(pow, safe=True) == (None, None, None, None)
    assert signature(p, safe=True) == (None, None, None, None)
    assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '')
    assert signature(p3, safe=True) == (('y',), {'!x': 0}, '', '')
    if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow
        assert isvalid(pow, 0,1) == True
        assert isvalid(pow, 0) == False
        assert isvalid(pow) == False
    else: # python >= 3.5 bug in ArgSpec for pow, so use min
        assert isvalid(min, 0,1) == True
        assert isvalid(min, 0) == False
        assert isvalid(min) == False
    assert isvalid(p, 0,1) == False
    assert isvalid(p, 0) == False
    assert isvalid(p) == False
    assert isvalid(p2, 0,1) == False
    assert isvalid(p2, 0) == False
    assert isvalid(p2) == False
github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_special():
    p = partial(add, 0,x=0)
    p2 = partial(add, z=0)
    p3 = partial(add, 0)

    
    if IS_PYPY: # builtins in PYPY are python functions
        assert signature(pow, safe=True) == (('base', 'exponent', 'modulus'), {'modulus': None}, '', '')
    else:
        assert signature(pow, safe=True) == (None, None, None, None)
    assert signature(p, safe=True) == (None, None, None, None)
    assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '')
    assert signature(p3, safe=True) == (('y',), {'!x': 0}, '', '')
    if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow
        assert isvalid(pow, 0,1) == True
        assert isvalid(pow, 0) == False
        assert isvalid(pow) == False
    else: # python >= 3.5 bug in ArgSpec for pow, so use min
        assert isvalid(min, 0,1) == True
        assert isvalid(min, 0) == False
        assert isvalid(min) == False
    assert isvalid(p, 0,1) == False
    assert isvalid(p, 0) == False
    assert isvalid(p) == False
    assert isvalid(p2, 0,1) == False
    assert isvalid(p2, 0) == False
    assert isvalid(p2) == False
    assert isvalid(p3, 0,1) == False
    assert isvalid(p3, 0) == True
github uqfoundation / klepto / tests / test_ignore.py View on Github external
def test_special():
    p = partial(add, 0,x=0)
    p2 = partial(add, z=0)
    p3 = partial(add, 0)

    
    if IS_PYPY: # builtins in PYPY are python functions
        assert signature(pow, safe=True) == (('base', 'exponent', 'modulus'), {'modulus': None}, '', '')
    else:
        assert signature(pow, safe=True) == (None, None, None, None)
    assert signature(p, safe=True) == (None, None, None, None)
    assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '')
    assert signature(p3, safe=True) == (('y',), {'!x': 0}, '', '')
    if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow
        assert isvalid(pow, 0,1) == True
        assert isvalid(pow, 0) == False
        assert isvalid(pow) == False
    else: # python >= 3.5 bug in ArgSpec for pow, so use min
        assert isvalid(min, 0,1) == True
        assert isvalid(min, 0) == False
        assert isvalid(min) == False
    assert isvalid(p, 0,1) == False
    assert isvalid(p, 0) == False
    assert isvalid(p) == False
    assert isvalid(p2, 0,1) == False
    assert isvalid(p2, 0) == False
github uqfoundation / klepto / tests / test_ignore.py View on Github external
s = signature(bar)
    assert s == (('x', 'y', 'z', 'a', 'b'), {'a': 1, 'b': 2}, 'args', '')

    # a partial with a 'fixed' x, thus x is 'unsettable' as a keyword
    p = partial(bar, 0)
    s = signature(p)
    assert s == (('y', 'z', 'a', 'b'), {'a': 1, '!x': 0, 'b': 2}, 'args', '')
    '''
    >>> p(0,1)  
        4
    >>> p(0,1,2,3,4,5)
        6
    '''
    # a partial where y is 'unsettable' as a positional argument
    p = partial(bar, y=10)
    s = signature(p)
    assert s == (('x', '!y', 'z', 'a', 'b'), {'a': 1, 'y': 10, 'b': 2}, 'args', '')
    '''
    >>> p(0,1,2)