How to use the executing.executing.NotOneValueFound function in executing

To help you get started, we’ve selected a few executing 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 alexmojaki / executing / executing / executing.py View on Github external
tree.body = [stmt]
                            ast.copy_location(tree, stmt)
                            try:
                                node = NodeFinder(frame, stmts, tree, lasti).result
                                break
                            except Exception:
                                pass
                    else:
                        try:
                            node = NodeFinder(frame, stmts, source.tree, lasti).result
                        except Exception as e:
                            # These exceptions can be caused by the source code having changed
                            # so the cached Source doesn't match the running code
                            # (e.g. when using IPython %autoreload)
                            # Try again with a fresh Source object
                            if retry_cache and isinstance(e, (NotOneValueFound, AssertionError)):
                                return find(
                                    source=cls.for_frame(frame, use_cache=False),
                                    retry_cache=False,
                                )
                            if TESTING:
                                raise

                    if node:
                        new_stmts = {statement_containing_node(node)}
                        assert_(new_stmts <= stmts)
                        stmts = new_stmts

                return source, node, stmts
github alexmojaki / executing / executing / executing.py View on Github external
def only(it):
    if hasattr(it, '__len__'):
        if len(it) != 1:
            raise NotOneValueFound('Expected one value, found %s' % len(it))
        # noinspection PyTypeChecker
        return list(it)[0]

    lst = tuple(islice(it, 2))
    if len(lst) == 0:
        raise NotOneValueFound('Expected one value, found 0')
    if len(lst) > 1:
        raise NotOneValueFound('Expected one value, found several')
    return lst[0]
github alexmojaki / executing / executing / executing.py View on Github external
def only(it):
    if hasattr(it, '__len__'):
        if len(it) != 1:
            raise NotOneValueFound('Expected one value, found %s' % len(it))
        # noinspection PyTypeChecker
        return list(it)[0]

    lst = tuple(islice(it, 2))
    if len(lst) == 0:
        raise NotOneValueFound('Expected one value, found 0')
    if len(lst) > 1:
        raise NotOneValueFound('Expected one value, found several')
    return lst[0]
github alexmojaki / executing / executing / executing.py View on Github external
def only(it):
    if hasattr(it, '__len__'):
        if len(it) != 1:
            raise NotOneValueFound('Expected one value, found %s' % len(it))
        # noinspection PyTypeChecker
        return list(it)[0]

    lst = tuple(islice(it, 2))
    if len(lst) == 0:
        raise NotOneValueFound('Expected one value, found 0')
    if len(lst) > 1:
        raise NotOneValueFound('Expected one value, found several')
    return lst[0]