def test_list_bindings(): """ ..code:: python List(expr* elts, expr_context ctx) """ node = _parse("[a, b, c]") assert list(get_bindings(node)) == []
def test_unary_op_bindings(): """ ..code:: python UnaryOp(unaryop op, expr operand) """ node = _parse("-a") assert list(get_bindings(node)) == []
def test_dict_bindings(): """ ..code:: python Dict(expr* keys, expr* values) """ node = _parse("{key: value}") assert list(get_bindings(node)) == []
def test_global_bindings(): """ ..code:: python Global(identifier* names) """ node = _parse("global name") assert list(get_bindings(node)) == ["name"]
def test_named_expr_bindings(): """ ..code:: python NamedExpr(expr target, expr value) """ node = _parse("(a := b)") assert list(get_bindings(node)) == ["a"]
def test_async_with_bindings_tuple(): node = _parse( """ async with A() as (a, b): pass """ ) assert list(get_bindings(node)) == ["a", "b"]
def test_raise_bindings(): """ ..code:: python Raise(expr? exc, expr? cause) """ node = _parse("raise TypeError()") assert list(get_bindings(node)) == []
def test_delete_bindings(): """ ..code:: python Delete(expr* targets) """ node = _parse("del something") assert list(get_bindings(node)) == []
def test_assign_bindings(): """ ..code:: python Assign(expr* targets, expr value, string? type_comment) """ node = _parse("a = b") assert list(get_bindings(node)) == ["a"]
def test_class_def_bindings_walrus_metaclass(): node = _parse( """ class Class(metaclass=(class_meta := MetaClass)): pass """ ) assert list(get_bindings(node)) == ["class_meta", "Class"]
def test_class_def_bindings_walrus_body(): node = _parse( """ class Class: a = (prop := 2) """ ) assert list(get_bindings(node)) == ["Class"]
def test_class_def_bindings_walrus_base(): node = _parse( """ class ClassName(BaseClass, (OtherBase := namedtuple())): pass """ ) assert list(get_bindings(node)) == ["OtherBase", "ClassName"]
def test_formatted_value_bindings(): """ ..code:: python FormattedValue(expr value, int conversion, expr? format_spec) """ node = _parse("f'{a} {b} {c}'") assert list(get_bindings(node)) == []
def test_tuple_bindings(): """ ..code:: python Tuple(expr* elts, expr_context ctx) """ node = _parse("(a, b, c)") assert list(get_bindings(node)) == []
def test_async_with_bindings_multiple(): node = _parse( """ async with A() as a, B() as b: pass """ ) assert list(get_bindings(node)) == ["a", "b"]
def test_aug_assign_bindings(): """ ..code:: python AugAssign(expr target, operator op, expr value) """ node = _parse("a += b") assert list(get_bindings(node)) == ["a"]
def test_async_with_bindings_unbound(): node = _parse( """ async with A(): pass """ ) assert list(get_bindings(node)) == []
def test_function_def_bindings(): node = _parse( """ def function(): name """ ) assert list(get_bindings(node)) == ["function"]
def test_async_with_bindings_walrus(): node = _parse( """ async with (ctx := A()) as a: pass """ ) assert list(get_bindings(node)) == ["ctx", "a"]
def test_async_for_bindings_walrus(): node = _parse( """ async for i in (r := range(10)): pass """ ) assert list(get_bindings(node)) == ["i", "r"]
def test_import_bindings(): """ ..code:: python Import(alias* names) """ node = _parse("import something") assert list(get_bindings(node)) == ["something"]
def test_function_def_bindings_walrus_default(): node = _parse( """ def function(a, b = (b_binding := 2)): pass """ ) assert list(get_bindings(node)) == ["function", "b_binding"]
def test_non_local_bindings(): """ ..code:: python Nonlocal(identifier* names) """ node = _parse("nonlocal name") assert list(get_bindings(node)) == ["name"]
def test_while_bindings_walrus_test(): node = _parse( """ while (value := test): pass """ ) assert list(get_bindings(node)) == ["value"]
def test_named_expr_bindings_recursive(): """ ..code:: python NamedExpr(expr target, expr value) """ node = _parse("(a := (b := (c := d)))") assert list(get_bindings(node)) == ["a", "b", "c"]
def test_if_bindings_walrus_test(): node = _parse( """ if (result := predicate()): pass """ ) assert list(get_bindings(node)) == ["result"]
def test_if_exp_bindings(): """ ..code:: python IfExp(expr test, expr body, expr orelse) """ node = _parse("subsequent() if predicate() else alternate()") assert list(get_bindings(node)) == []
def test_function_def_bindings_walrus_kw_default(): node = _parse( """ def function(*, kw1 = (kw1_binding := 1), kw2): pass """ ) assert list(get_bindings(node)) == ["function", "kw1_binding"]
def test_set_bindings(): """ ..code:: python Set(expr* elts) """ node = _parse("{a, b, c}") assert list(get_bindings(node)) == []
def test_name_bindings(): """ ..code:: python Name(identifier id, expr_context ctx) """ node = _parse("a") assert list(get_bindings(node)) == []