Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def pop_first_of(source, *keys, **kwargs):
    '''Similar to :func:`get_first_of` using as `source` either an object or a
    mapping and deleting the first attribute or key.


        >>> somedict = dict(bar='bar-dict', eggs='eggs-dict')

        >>> class Foo(object): pass
        >>> foo = Foo()
        >>> foo.bar = 'bar-obj'
        >>> foo.eggs = 'eggs-obj'

        >>> pop_first_of((somedict, foo), 'eggs')

        >>> pop_first_of((somedict, foo), 'eggs')

        >>> pop_first_of((somedict, foo), 'eggs') is None

        >>> pop_first_of((foo, somedict), 'bar')

        >>> pop_first_of((foo, somedict), 'bar')

        >>> pop_first_of((foo, somedict), 'bar') is None

    from xoutil.types import is_collection
    def inner(source):
        get = smart_getter_and_deleter(source)
        res, i = Unset, 0
        while (res is Unset) and (i < len(keys)):
            res = get(keys[i], Unset)
            i += 1
        return res

    if is_collection(source):
        res = Unset
        source = iter(source)
        probe = next(source, None)
        while res is Unset and probe:
            res = inner(probe)
            probe = next(source, None)
        res = inner(source)
    return res if res is not Unset else kwargs.get('default', None)

src/x/o/xoutil-1.5.4/xoutil/annotate.py   xoutil(Download)
    from xoutil.objects import pop_first_of
    func.__annotations__ = annotations = getattr(func, '__annotations__', {})
    if signature:
        annotations.update({argname: value
                            for argname, value in _parse_signature(signature)})
    probes = ('return_annotation', '_return', '__return')
    return_annotation_kwarg = pop_first_of(keyword_annotations, *probes)