How to use the ring.callable.Callable function in ring

To help you get started, we’ve selected a few ring 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 youknowone / ring / tests / test_callable.py View on Github external
assert w.is_classmethod is False

    class A():

        def m(self):
            pass
        w = Callable(m)
        assert w.is_barefunction is False
        assert w.is_descriptor is False
        assert w.is_membermethod is True
        assert w.is_classmethod is False

        @classmethod
        def c(cls):
            pass
        w = Callable(c)
        assert w.is_barefunction is False
        assert w.is_descriptor is True
        assert w.is_membermethod is False
        assert w.is_classmethod is True

        @staticmethod
        def s():
            pass
        w = Callable(s)
        assert w.is_barefunction is False
        assert w.is_descriptor is True
        assert w.is_membermethod is False
        assert w.is_classmethod is False
github youknowone / ring / tests / test_callable.py View on Github external
def test_callable_attributes():

    def f():
        pass
    w = Callable(f)
    assert w.is_barefunction is True
    assert w.is_descriptor is False
    assert w.is_membermethod is False
    assert w.is_classmethod is False

    class A():

        def m(self):
            pass
        w = Callable(m)
        assert w.is_barefunction is False
        assert w.is_descriptor is False
        assert w.is_membermethod is True
        assert w.is_classmethod is False

        @classmethod
github youknowone / ring / tests / test_callable.py View on Github external
def test_kwargify_exc(f, args, kwargs, exc):
    with pytest.raises(exc):
        Callable(f).kwargify(args, kwargs)
github youknowone / ring / tests / _test_callable_py3.py View on Github external
def test_kwargify_py3(f, args, kwargs, merged):
    kwargified = Callable(f).kwargify(args, kwargs)
    print(kwargified)
    print(merged)
    assert kwargified == merged, (kwargified, merged)
github youknowone / ring / tests / _test_callable_py3.py View on Github external
def test_annotations():
    def f(a: int, b: str, *c, d: Any = 10, **e) -> Optional[float]:
        pass

    c = Callable(f)
    assert c.annotations == {'a': int, 'b': str, 'd': Any, 'return': Optional[float]}
github youknowone / ring / tests / _test_callable_py3.py View on Github external
def test_kwargify_exc_py3(f, args, kwargs, exc):
    with pytest.raises(exc):
        Callable(f).kwargify(args, kwargs)
github youknowone / ring / tests / test_callable.py View on Github external
def test_empty_annotations():
    c = Callable(lambda a, *b, **c: None)
    assert c.annotations == {}
github youknowone / ring / ring / key.py View on Github external
def __init__(
            self, provider, indirect_marker='*', format_prefix=None,
            ignorable_keys=[], verbose=False):

        if not isinstance(provider, Callable):
            provider = Callable(provider)
        super(CallableKey, self).__init__(provider, indirect_marker)
        self.ignorable_keys = ignorable_keys
        if format_prefix is None:
            format_prefix = self.default_format_prefix
        if callable(format_prefix):
            format_prefix = format_prefix(provider)
        self.format = format_prefix + \
            self.default_format_body(
                self.ordered_provider_keys, verbose=verbose)
github youknowone / ring / ring / func / base.py View on Github external
def create_key_builder(
        c, key_prefix, ignorable_keys, coerce=coerce, encoding=None,
        key_refactor=None, in_memory_storage=False):
    assert isinstance(c, Callable)
    key_generator = CallableKey(
        c, format_prefix=key_prefix, ignorable_keys=ignorable_keys)

    def compose_key(*bound_args, **kwargs):
        full_kwargs = kwargs.copy()
        for i, prearg in enumerate(bound_args):
            full_kwargs[c.parameters[i].name] = bound_args[i]
        coerced_kwargs = {
            k: coerce(v, in_memory_storage) for k, v in full_kwargs.items()
            if k not in ignorable_keys}
        key = key_generator.build(coerced_kwargs)
        if encoding:
            key = key.encode(encoding)
        if key_refactor:
            key = key_refactor(key)
        return key
github youknowone / ring / ring / func / base.py View on Github external
def asyncio_binary_classifier(f):
    c = Callable(f)
    return int(bool(c.is_coroutine))