Nodes References Page — RedBaron 0.8 documentation

This is the reference page for every node type encountered in RedBaron and their specificities.

# Nodes References Page

# TopClass

## CodeBlockNode

CodeBlockNode is a type of node that has a body composed of indented code like the DefNode or the IfNode. Great care has been taken on the SetAttr of their value so you don’t have to take care about reindenting and other formatting details.

Demonstration:

    In [1]: red = RedBaron("def function():\n    pass\n")

    In [2]: red
    Out[2]:
    0   def function():
            pass

    In [3]: red[0].value = "stuff"  # first '\n' will be added, indentation will be set

    In [4]: red
    Out[4]:
    0   def function():
            stuff

    In [5]: red[0].value = "                    bad_indent"

    In [6]: red
    Out[6]:
    0   def function():
            bad_indent

    In [7]: red[0].value = " some\n stuff"

    In [8]: red
    Out[8]:
    0   def function():
            some
            stuff

Some for indented cases:

    In [9]: red = RedBaron("class A:\n    def __init__():\n        pass\n\n    def plop():\n        pass")

    In [10]: red.def_.value = "not_indented"

    In [11]: red
    Out[11]:
    0   class A:
            def __init__():
                not_indented

            def plop():
                pass

    In [12]: red.def_.value = "\n                              badly_indented"

    In [13]: red
    Out[13]:
    0   class A:
            def __init__():
                badly_indented

            def plop():
                pass

    In [14]: red.def_.value = "some\nstuff\nfoo\nbar\n\npouet"

    In [15]: red
    Out[15]:
    0   class A:
            def __init__():
                some
                stuff
                foo
                bar

                pouet

            def plop():
                pass

# Nodes

## ArgumentGeneratorComprehensionNode

A node representing generator passed as an argument during a function call.

    In [16]: RedBaron("a(x for y in z)")[0].value[1].value[0].help(deep=True)
    ArgumentGeneratorComprehensionNode()
      # identifiers: argument_generator_comprehension, argument_generator_comprehension_, argumentgeneratorcomprehension, argumentgeneratorcomprehensionnode
      result ->
        NameNode()
          # identifiers: name, name_, namenode
          value='x'
      generators ->
        * ComprehensionLoopNode()
            # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
            iterator ->
              NameNode()
                # identifiers: name, name_, namenode
                value='y'
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='z'
            ifs ->

### SetAttr

    In [17]: red = RedBaron("a(x for y in z)")

    In [18]: red
    Out[18]: 0   a(x for y in z)

    In [19]: red[0].value[1].value[0].result = "pouet"

    In [20]: red
    Out[20]: 0   a(pouet for y in z)

    In [21]: red[0].value[1].value[0].generators = "for artichaut in courgette"

    In [22]: red
    Out[22]: 0   a(pouet for artichaut in courgette)

## AssertNode

A node representing the assert statement.

    In [23]: RedBaron("assert test, message")[0].help(deep=True)
    AssertNode()
      # identifiers: assert, assert_, assertnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='test'
      message ->
        NameNode()
          # identifiers: name, name_, namenode
          value='message'

### SetAttr

    In [24]: red = RedBaron("assert some_test")

    In [25]: red
    Out[25]: 0   assert some_test

    In [26]: red[0].value = "1 == caramba()"

    In [27]: red
    Out[27]: 0   assert 1 == caramba()

    In [28]: red[0].message = "'foo bar'"

    In [29]: red
    Out[29]: 0   assert 1 == caramba(), 'foo bar'

    In [30]: red[0].message = ""

    In [31]: red
    Out[31]: 0   assert 1 == caramba()

## AssignmentNode

A node representing the assign operation in python (`foo = bar`) and the “augmented” assign (`foo += bar`).

    In [32]: RedBaron("a = b")[0].help(deep=True)
    AssignmentNode()
      # identifiers: assign, assignment, assignment_, assignmentnode
      operator=''
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      annotation ->
        None
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

    In [33]: RedBaron("a += b")[0].help(deep=True)
    AssignmentNode()
      # identifiers: assign, assignment, assignment_, assignmentnode
      operator='+'
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      annotation ->
        None
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

### SetAttr

Works as expected:

    In [34]: red = RedBaron("a = b")

    In [35]: red[0].first = "caramba"

    In [36]: red
    Out[36]: 0   a = b

    In [37]: red[0].second = "42"

    In [38]: red
    Out[38]: 0   a = b

For the operator part, expected input should work:

    In [39]: red = RedBaron("a = b")

    In [40]: red[0].operator = "+="

    In [41]: red
    Out[41]: 0   a += b

    In [42]: red[0].operator = "+" # equivalent to '+='

    In [43]: red
    Out[43]: 0   a += b

    In [44]: red[0].operator = "-" # equivalent to '-='

    In [45]: red
    Out[45]: 0   a -= b

    In [46]: red[0].operator = "=" # equivalent to '='

    In [47]: red
    Out[47]: 0   a = b

    In [48]: red[0].operator = "/="

    In [49]: red
    Out[49]: 0   a /= b

    In [50]: red[0].operator = "" # equivalent to '='

    In [51]: red
    Out[51]: 0   a = b

## AssociativeParenthesisNode

This node represents a statement prioritised on another by being surrounded by parenthesis. For e.g., the first part of this addition: `(1 + 1) * 2`.

    In [52]: RedBaron("(foo)")[0].help(deep=True)
    AssociativeParenthesisNode()
      # identifiers: associative_parenthesis, associative_parenthesis_, associativeparenthesis, associativeparenthesisnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='foo'

### SetAttr

    In [53]: red = RedBaron("(foo)")

    In [54]: red
    Out[54]: 0   (foo)

    In [55]: red[0].value = "1 + 1"

    In [56]: red
    Out[56]: 0   (1 + 1)

## AtomtrailersNode

This node represents a combination of NameNode, DotNode, CallNode, GetitemNode sorted in a list. For e.g.: `a.b().c[d]`.

    In [57]: RedBaron("a.b().c[d]")[0].help(deep=True)
    AtomtrailersNode()
      # identifiers: atomtrailers, atomtrailers_, atomtrailersnode
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='a'
        * NameNode()
            # identifiers: name, name_, namenode
            value='b'
        * CallNode()
            # identifiers: call, call_, callnode
            value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='c'
        * GetitemNode()
            # identifiers: getitem, getitem_, getitemnode
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='d'

### SetAttr

    In [58]: red = RedBaron("a.b()")

    In [59]: red
    Out[59]: 0   a.b()

    In [60]: red[0].value = "d.be"

    In [61]: red
    Out[61]: 0   d.be

## BinaryNode

The node represents a binary number value.

    In [62]: RedBaron("0b10101")[0].help(deep=True)
    BinaryNode()
      # identifiers: binary, binary_, binarynode
      value='0b10101'

## BinaryOperatorNode

The node represents a binary operator (an operator (e.g.: `+` `-` `/`..) applied to 2 values) with its operands. For e.g.: `1 + 1`.

    In [63]: RedBaron("1 + 1")[0].help(deep=True)
    BinaryOperatorNode()
      # identifiers: binary_operator, binary_operator_, binaryoperator, binaryoperatornode
      value='+'
      first ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'
      second ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'

### SetAttr

    In [64]: red = RedBaron("1 + 1")

    In [65]: red
    Out[65]: 0   1 + 1

    In [66]: red[0].value = "*"

    In [67]: red
    Out[67]: 0   1 * 1

    In [68]: red[0].first = "(1 + 1)"

    In [69]: red
    Out[69]: 0   (1 + 1) * 1

    In [70]: red[0].second = "caramba"

    In [71]: red
    Out[71]: 0   (1 + 1) * caramba

## BooleanOperatorNode

The node represents a boolean operator (an operator (e.g.: `and` `or`) applied to 2 values) with its operands. For e.g.: `x and y`.

    In [72]: RedBaron("x and y")[0].help(deep=True)
    BooleanOperatorNode()
      # identifiers: boolean_operator, boolean_operator_, booleanoperator, booleanoperatornode
      value='and'
      first ->
        NameNode()
          # identifiers: name, name_, namenode
          value='x'
      second ->
        NameNode()
          # identifiers: name, name_, namenode
          value='y'

### SetAttr

    In [73]: red = RedBaron("x and y")

    In [74]: red
    Out[74]: 0   x and y

    In [75]: red[0].value = "or"

    In [76]: red
    Out[76]: 0   x or y

    In [77]: red[0].first = "plop"

    In [78]: red
    Out[78]: 0   plop or y

    In [79]: red[0].second = "oupsi"

    In [80]: red
    Out[80]: 0   plop or oupsi

## CallNode

A node representing a call (eg: `a()`, here `a` is called with no arguments). It is always stored in an AtomtrailersNode or a DecoratorNode.

    In [81]: RedBaron("a(b, c=d)")[0].value[1].help(deep=True)
    CallNode()
      # identifiers: call, call_, callnode
      value ->
        * CallArgumentNode()
            # identifiers: call_argument, call_argument_, callargument, callargumentnode
            target ->
              None
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='b'
        * CallArgumentNode()
            # identifiers: call_argument, call_argument_, callargument, callargumentnode
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='c'
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='d'

### SetAttr

SetAttr works as expected:

    In [82]: red = RedBaron("a()")

    In [83]: red[0].value[1].value = "b, c=d, *e, **f"

    In [84]: red
    Out[84]: 0   a(b, c=d, *e, **f)

## CallArgumentNode

A node representing an argument or a named argument of a CallNode (other nodes that can be in a CallNode are ListArgumentNode and DictArgumentNode).

    In [85]: RedBaron("a(b, c=d)")[0].value[1].value[0].help(deep=True)
    CallArgumentNode()
      # identifiers: call_argument, call_argument_, callargument, callargumentnode
      target ->
        None
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

    In [86]: RedBaron("a(b, c=d)")[0].value[1].value[1].help(deep=True)
    CallArgumentNode()
      # identifiers: call_argument, call_argument_, callargument, callargumentnode
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='c'
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='d'

### SetAttr

    In [87]: red = RedBaron("a(b)")

    In [88]: red
    Out[88]: 0   a(b)

    In [89]: red[0].value[1].value[0] = "stuff=foo"

    In [90]: red
    Out[90]: 0   a(stuff=foo)

## ClassNode

A node representing a class definition.

    In [91]: RedBaron("class SomeAwesomeName(A, B, C): pass")[0].help(deep=True)
    ClassNode()
      # identifiers: class, class_, classnode
      # default test value: name
      name='SomeAwesomeName'
      parenthesis=True
      decorators ->
      inherit_from ->
        * TupleNode()
            # identifiers: tuple, tuple_, tuplenode
            with_parenthesis=False
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='A'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='B'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='C'
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

ClassNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Most other attributes work as expected:

    In [92]: red = RedBaron("class SomeAwesomeName(A, B, C): pass")

    In [93]: red[0].name = "AnotherAwesomeName"

    In [94]: red
    Out[94]:
    0   class AnotherAwesomeName(A, B, C): pass

    In [95]: red[0].inherit_from = "object"

    In [96]: red
    Out[96]:
    0   class AnotherAwesomeName(object): pass

## CommaNode

A node representing a comma, this is the kind of formatting node that you might have to deal with if not enough high level helpers are available. They are generally present in call, function arguments definition and data structure sugar syntactic notation.

The comma node is responsible for holding the formatting around it.

    In [97]: RedBaron("[1, 2, 3]")[0].value.node_list[1].help(deep=True)
    CommaNode()
      # identifiers: comma, comma_, commanode

## ComparisonNode

The node represents a comparison operation, for e.g.: `42 > 30`.

    In [98]: RedBaron("42 > 30")[0].help(deep=True)
    ComparisonNode()
      # identifiers: comparison, comparison_, comparisonnode
      first ->
        IntNode()
          # identifiers: int, int_, intnode
          value='42'
      value ->
        ComparisonOperatorNode()
          # identifiers: comparison_operator, comparison_operator_, comparisonoperator, comparisonoperatornode
          first='>'
          second=''
      second ->
        IntNode()
          # identifiers: int, int_, intnode
          value='30'

### SetAttr

    In [99]: red = RedBaron("42 > 30")

    In [100]: red
    Out[100]: 0   42 > 30

    In [101]: red[0].operator = "=="

    In [102]: red
    Out[102]: 0   42 > 30

    In [103]: red[0].first = "(1 + 1)"

    In [104]: red
    Out[104]: 0   (1 + 1) > 30

    In [105]: red[0].second = "caramba"

    In [106]: red
    Out[106]: 0   (1 + 1) > caramba

## ComprehensionIfNode

The node represents “if” condition in a comprehension loop. It is always a member of a ComprehensionLoopNode.

    In [107]: RedBaron("[x for x in x if condition]")[0].generators[0].ifs[0].help(deep=True)
    ComprehensionIfNode()
      # identifiers: comprehension_if, comprehension_if_, comprehensionif, comprehensionifnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='condition'

### SetAttr

    In [108]: red = RedBaron("[x for x in x if condition]")

    In [109]: red
    Out[109]: 0   [x for x in x if condition]

    In [110]: red[0].generators[0].ifs[0].value = "True"

    In [111]: red
    Out[111]: 0   [x for x in x if True]

## ComprehensionLoopNode

The node represents the loop part of a comprehension structure.

    In [112]: RedBaron("[x for y in z]")[0].generators[0].help(deep=True)
    ComprehensionLoopNode()
      # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
      iterator ->
        NameNode()
          # identifiers: name, name_, namenode
          value='y'
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='z'
      ifs ->

### SetAttr

    In [113]: red = RedBaron("[x for y in z]")

    In [114]: red
    Out[114]: 0   [x for y in z]

    In [115]: red[0].generators[0].target = "plop"

    In [116]: red
    Out[116]: 0   [x for y in plop]

    In [117]: red[0].generators[0].iterator = "iter"

    In [118]: red
    Out[118]: 0   [x for iter in plop]

    In [119]: red[0].generators[0].ifs = "if a if b"

    In [120]: red
    Out[120]: 0   [x for iter in plop if a if b]

## DecoratorNode

A node representing an individual decorator (of a function or a class).

    In [121]: RedBaron("@stuff.plop(*a)\ndef b(): pass")[0].decorators[0].help(deep=True)
    DecoratorNode()
      # identifiers: decorator, decorator_, decoratornode
      value ->
        DottedNameNode()
          # identifiers: dotted_name, dotted_name_, dottedname, dottednamenode
          value ->
            * NameNode()
                # identifiers: name, name_, namenode
                value='stuff'
            * DotNode()
                # identifiers: dot, dot_, dotnode
            * NameNode()
                # identifiers: name, name_, namenode
                value='plop'
      call ->
        CallNode()
          # identifiers: call, call_, callnode
          value ->
            * ListArgumentNode()
                # identifiers: list_argument, list_argument_, listargument, listargumentnode
                value ->
                  NameNode()
                    # identifiers: name, name_, namenode
                    value='a'
                annotation ->
                  None

### SetAttr

    In [122]: red = RedBaron("@stuff\ndef a(): pass")

    In [123]: red
    Out[123]:
    0   @stuff
        def a(): pass

    In [124]: red[0].decorators[0].value = "a.b.c"

    In [125]: red
    Out[125]:
    0   @a.b.c
        def a(): pass

    In [126]: red[0].decorators[0].call = "(*args)"

    In [127]: red
    Out[127]:
    0   @a.b.c(*args)
        def a(): pass

    In [128]: red[0].decorators[0].call = ""

    In [129]: red
    Out[129]:
    0   @a.b.c
        def a(): pass

## DefNode

A node representing a function definition.

    In [130]: RedBaron("def stuff():\n    pass\n")[0].help(deep=True)
    DefNode()
      # identifiers: def, def_, defnode, funcdef, funcdef_
      # default test value: name
      async=False
      name='stuff'
      return_annotation ->
        None
      decorators ->
      arguments ->
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

DefNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Most other attributes works as expected:

    In [131]: red = RedBaron("def stuff():\n    body\n")

    In [132]: red[0]
    Out[132]:
    def stuff():
        body

    In [133]: red[0].name = "awesome_function"

    In [134]: red[0].arguments = "a, b=None, *c, **d"

    In [135]: red
    Out[135]:
    0   def awesome_function(a, b=None, *c, **d):
            body

Decorators might be a bit less intuitive:

    In [136]: red =  RedBaron("def stuff():\n    body\n")

    In [137]: red[0].decorators = "@foo(*plop)"

    In [138]: red
    Out[138]:
    0   @foo(*plop)
        def stuff():
            body

    In [139]: red[0].decorators = "@foo\n@bar.baz()"

    In [140]: red
    Out[140]:
    0   @foo
        @bar.baz()
        def stuff():
            body

    In [141]: red[0].decorators = "    @pouet"  # SetAttr will take care of reindenting everything as expected

    In [142]: red
    Out[142]:
    0   @pouet
        def stuff():
            body

New in 0.7.

Async is a boolean attribute that determine if a function is async:

    In [143]: red =  RedBaron("def stuff():\n    body\n")

    In [144]: red[0].async_
    Out[144]: False

    In [145]: red[0].async_ = True

    In [146]: red
    Out[146]:
    0   async def stuff():
            body

    In [147]: red[0].async_ = False

    In [148]: red
    Out[148]:
    0   def stuff():
            body

Warning

As of python 3.7 async and await are now reserved keywords so don’t uses red.async, it works as expected but won’t make your code forward compatible.

New in 0.9

Return annotation management:

    In [149]: red =  RedBaron("def stuff():\n    return 42\n")

    In [150]: red
    Out[150]:
    0   def stuff():
            return 42

    In [151]: red[0].return_annotation = "Int"

    In [152]: red
    Out[152]:
    0   def stuff() -> Int:
            return 42

    In [153]: red[0].return_annotation = ""

    In [154]: red
    Out[154]:
    0   def stuff():
            return 42

## DefArgumentNode

A node representing an argument in a function definition.

    In [155]: RedBaron("def a(b, c=d): pass")[0].arguments.help(deep=True)
    0 -----------------------------------------------------
    DefArgumentNode()
      # identifiers: def_argument, def_argument_, defargument, defargumentnode
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      annotation ->
        None
      value ->
        None
    1 -----------------------------------------------------
    CommaNode()
      # identifiers: comma, comma_, commanode
    2 -----------------------------------------------------
    DefArgumentNode()
      # identifiers: def_argument, def_argument_, defargument, defargumentnode
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='c'
      annotation ->
        None
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='d'

### SetAttr

    In [156]: red = RedBaron("def a(b): pass")

    In [157]: red
    Out[157]:
    0   def a(b): pass

    In [158]: red[0].arguments[0].name = "plop"

    In [159]: red
    Out[159]:
    0   def a(b): pass

    In [160]: red[0].arguments[0].value = "1 + 1"

    In [161]: red
    Out[161]:
    0   def a(b=1 + 1): pass

New in 0.9

Annotations:

    In [162]: red = RedBaron("def a(b): pass")

    In [163]: red
    Out[163]:
    0   def a(b): pass

    In [164]: red[0].arguments[0].annotation = "Int"

    In [165]: red
    Out[165]:
    0   def a(b : Int): pass

    In [166]: red[0].arguments[0].annotation
    Out[166]: Int

    In [167]: red
    Out[167]:
    0   def a(b : Int): pass

## DelNode

A node representing a `del` statement.

    In [168]: RedBaron("del stuff")[0].help(deep=True)
    DelNode()
      # identifiers: del, del_, delnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='stuff'

### SetAttr

    In [169]: red = RedBaron("del stuff")

    In [170]: red
    Out[170]: 0   del stuff

    In [171]: red[0].value = "some, other, stuff"

    In [172]: red
    Out[172]: 0   del some, other, stuff

## DictArgumentNode

A node representing a ‘kwargs’ defined in a function definition argument or used in a CallNode.

    In [173]: RedBaron("a(**b)")[0].value[1].value[0].help(deep=True)
    DictArgumentNode()
      # identifiers: dict_argument, dict_argument_, dictargument, dictargumentnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      annotation ->
        None

### SetAttr

    In [174]: red = RedBaron("a(**b)")

    In [175]: red
    Out[175]: 0   a(**b)

    In [176]: red[0].value[1].value[0].value = "plop"

    In [177]: red
    Out[177]: 0   a(**plop)

New in 0.9

Annotations:

    In [178]: red = RedBaron("def a(**b): pass")

    In [179]: red
    Out[179]:
    0   def a(**b): pass

    In [180]: red[0].arguments[0].annotation = "Int"

    In [181]: red
    Out[181]:
    0   def a(**b : Int): pass

    In [182]: red[0].arguments[0].annotation
    Out[182]: Int

    In [183]: red
    Out[183]:
    0   def a(**b : Int): pass

## DictNode

A node representing python sugar syntactic notation for dict.

    In [184]: RedBaron("{'a': 1, 'b': 2, 'c': 3}")[0].help(deep=True)
    DictNode()
      # identifiers: dict, dict_, dictnode
      value ->
        * DictitemNode()
            # identifiers: dictitem, dictitem_, dictitemnode
            key ->
              StringNode()
                # identifiers: string, string_, stringnode
                value="'a'"
            value ->
              IntNode()
                # identifiers: int, int_, intnode
                value='1'
        * DictitemNode()
            # identifiers: dictitem, dictitem_, dictitemnode
            key ->
              StringNode()
                # identifiers: string, string_, stringnode
                value="'b'"
            value ->
              IntNode()
                # identifiers: int, int_, intnode
                value='2'
        * DictitemNode()
            # identifiers: dictitem, dictitem_, dictitemnode
            key ->
              StringNode()
                # identifiers: string, string_, stringnode
                value="'c'"
            value ->
              IntNode()
                # identifiers: int, int_, intnode
                value='3'

## DictComprehensionNode

A node representing dictionary comprehension node.

    In [185]: RedBaron("{a: b for c in d}")[0].help(deep=True)
    DictComprehensionNode()
      # identifiers: dict_comprehension, dict_comprehension_, dictcomprehension, dictcomprehensionnode
      result ->
        DictitemNode()
          # identifiers: dictitem, dictitem_, dictitemnode
          key ->
            NameNode()
              # identifiers: name, name_, namenode
              value='a'
          value ->
            NameNode()
              # identifiers: name, name_, namenode
              value='b'
      generators ->
        * ComprehensionLoopNode()
            # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
            iterator ->
              NameNode()
                # identifiers: name, name_, namenode
                value='c'
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='d'
            ifs ->

### SetAttr

    In [186]: red = RedBaron("{a: b for c in d}")

    In [187]: red
    Out[187]: 0   {a: b for c in d}

    In [188]: red[0].result = "plop: poulpe"

    In [189]: red
    Out[189]: 0   {plop: poulpe for c in d}

    In [190]: red[0].generators = "for zomg in wtf"

    In [191]: red
    Out[191]: 0   {plop: poulpe for zomg in wtf}

## DottedAsNameNode

A node representing an argument to the import node.

    In [192]: RedBaron("import a.b.c as d")[0].value[0].help(deep=True)
    DottedAsNameNode()
      # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
      target='d'
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='a'
        * NameNode()
            # identifiers: name, name_, namenode
            value='b'
        * NameNode()
            # identifiers: name, name_, namenode
            value='c'

### SetAttr

    In [193]: red = RedBaron("import a.b.c as d")

    In [194]: red
    Out[194]: 0   import a.b.c as d

    In [195]: red[0].value[0].value = "some.random.module"

    In [196]: red
    Out[196]: 0   import some.random.module as d

    In [197]: red[0].value[0].target = "stuff"

    In [198]: red
    Out[198]: 0   import some.random.module as stuff

## DotNode

A node representing a dot ‘.’, generally found in atom trailers (this kind of structure: ‘variable.another_variable(call)[getitem]’). This is the kind of formatting node that you might have to deal with if not enough high level helpers are available.

The dot node is responsible for holding the formatting around it.

    In [199]: RedBaron("a.b")[0].value[1].help(deep=True)
    NameNode()
      # identifiers: name, name_, namenode
      value='b'

## ElifNode

A node representing an elif statement.

The ElifNode, like the IfNode or the ElseNode are stored in a IfelseblockNode.

    In [200]: RedBaron("if a: pass\nelif b: pass")[0].value[1].help(deep=True)
    ElifNode()
      # identifiers: elif, elif_, elifnode
      test ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

ElifNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Other attributes work as expected:

    In [201]: red = RedBaron("if a: pass\nelif b: pass")

    In [202]: red
    Out[202]:
    0   if a: pass
        elif b: pass

    In [203]: red[0].value[1].test = "1 + 1 == 11"

    In [204]: red
    Out[204]:
    0   if a: pass
        elif 1 + 1 == 11: pass

## ElseNode

A node representing an else statement.

The ElseNode, like the IfNode or the ElifNode, is stored in a IfelseblockNode.

    In [205]: RedBaron("if a: pass\nelse: pass")[0].value[1].help(deep=True)
    ElseNode()
      # identifiers: else, else_, elsenode
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

ElifNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information.

## EllipsisNode

A node representing “…”.

    In [206]: RedBaron("def a(): ...").ellipsis.help(deep=True)
    EllipsisNode()
      # identifiers: ellipsis, ellipsis_, ellipsisnode

## EndlNode

A node for the end line (‘n’, ‘rn’) component.

This node is responsible for holding the indentation AFTER itself. This node also handles formatting around it, CommentNode before an EndlNode will end up in the formatting key of an EndlNode 99% of the time (the exception is if the CommentNode is the last node of the file).

    In [207]: RedBaron("\n")[0].help()
    EndlNode()
      # identifiers: endl, endl_, endlnode
      value='\n'
      indent=''

    In [208]: RedBaron("# first node of the file\n# last node of the file").node_list.help()
    0 -----------------------------------------------------
    CommentNode()
      # identifiers: comment, comment_, commentnode
      value='# first node of the file'
    1 -----------------------------------------------------
    EndlNode()
      # identifiers: endl, endl_, endlnode
      value='\n'
      indent=''
    2 -----------------------------------------------------
    CommentNode()
      # identifiers: comment, comment_, commentnode
      value='# last node of the file'

## ExceptNode

A node representing an except statement (member of a TryNode).

    In [209]: RedBaron("try: pass\nexcept FooBar: pass\nexcept Exception: pass\nelse: pass\nfinally: pass\n")[0].excepts[0].help(deep=True)
    ExceptNode()
      # identifiers: except, except_, exceptnode
      delimiter=''
      exception ->
        NameNode()
          # identifiers: name, name_, namenode
          value='FooBar'
      target ->
        None
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

ExceptNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Other attributes work as expected:

    In [210]: red = RedBaron("try: pass\nexcept: pass")

    In [211]: red
    Out[211]:
    0   try: pass
        except: pass

    In [212]: red[0].excepts[0].exception = "plop"

    In [213]: red
    Out[213]:
    0   try: pass
        except plop: pass

    In [214]: red[0].excepts[0].target = "stuff"

    In [215]: red
    Out[215]:
    0   try: pass
        except plop as stuff: pass

    In [216]: red[0].excepts[0].exception = ""

    In [217]: red
    Out[217]:
    0   try: pass
        except: pass

    # red[0].excepts[0].target = "stuff" <- would raise without a target

## ExecNode

A node representing an exec statement.

    In [218]: RedBaron("exec '1 + 1' in a, b")[0].help(deep=True)
    ExecNode()
      # identifiers: exec, exec_, execnode
      value ->
        StringNode()
          # identifiers: string, string_, stringnode
          value="'1 + 1'"
      globals ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      locals ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

### SetAttr

    In [219]: red = RedBaron("exec 'stuff'")

    In [220]: red
    Out[220]: 0   exec 'stuff'

    In [221]: red[0].value = 'some_code'

    In [222]: red
    Out[222]: 0   exec some_code

    In [223]: red[0].globals = 'x'

    In [224]: red
    Out[224]: 0   exec some_code in x

    In [225]: red[0].locals = 'y'

    In [226]: red
    Out[226]: 0   exec some_code in x, y

## FinallyNode

A node representing a finally statement (member of a TryNode).

    In [227]: RedBaron("try: pass\nexcept FooBar: pass\nexcept Exception: pass\nelse: pass\nfinally: pass\n").finally_.help(deep=True)
    FinallyNode()
      # identifiers: finally, finally_, finallynode
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

FinallyNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information.

## ForNode

A node representing a for loop.

    In [228]: RedBaron("for i in b:\n    pass")[0].help(deep=True)
    ForNode()
      # identifiers: for, for_, fornode
      async=False
      iterator ->
        NameNode()
          # identifiers: name, name_, namenode
          value='i'
      target ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      else ->
        None
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

ForNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. The else attributes accept a great ranges of inputs, since `else` is a reserved python keyword, you need to access it using the `else_` attribute. Other attributes work as expected:

    In [229]: red = RedBaron("for i in b: pass")

    In [230]: red
    Out[230]:
    0   for i in b: pass

    In [231]: red[0].iterator = "i, j, k"

    In [232]: red
    Out[232]:
    0   for i, j, k in b: pass

    In [233]: red[0].target = "[x for x in stuff if condition]"

    In [234]: red
    Out[234]:
    0   for i, j, k in [x for x in stuff if condition]: pass

    In [235]: red[0].else_ = "do_stuff"

    In [236]: red
    Out[236]:
    0   for i, j, k in [x for x in stuff if condition]: pass
        else:
            do_stuff

    In [237]: red[0].else_ = "else: foobar"

    In [238]: red
    Out[238]:
    0   for i, j, k in [x for x in stuff if condition]: pass
        else:
            foobar

    In [239]: red[0].else_ = "    else:\n        badly_indented_and_trailing\n\n\n\n"

    In [240]: red
    Out[240]:
    0   for i, j, k in [x for x in stuff if condition]: pass
        else:
            badly_indented_and_trailing

New in 0.8.

Async is a boolean attribute that determine if a function is async:

    In [241]: red =  RedBaron("for a in b: pass")

    In [242]: red[0].async_
    Out[242]: False

    In [243]: red[0].async_ = True

    In [244]: red
    Out[244]:
    0   async for a in b: pass

    In [245]: red[0].async_ = False

    In [246]: red
    Out[246]:
    0   for a in b: pass

Warning

As of python 3.7 async and await are now reserved keywords so don’t uses red.async, it works as expected but won’t make your code forward compatible.

## FromImportNode

A node representing a “from import” statement.

    In [247]: RedBaron("from a import b")[0].help(deep=True)
    FromImportNode()
      # identifiers: from_import, from_import_, fromimport, fromimportnode
      # helpers: full_path_modules, full_path_names, modules, names
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='a'
      targets ->
        * NameAsNameNode()
            # identifiers: name_as_name, name_as_name_, nameasname, nameasnamenode
            value='b'
            target=''

### SetAttr

    In [248]: red = RedBaron("from a import b")

    In [249]: red
    Out[249]: 0   from a import b

    In [250]: red[0].value = "some.module"

    In [251]: red
    Out[251]: 0   from some.module import b

    In [252]: red[0].targets = "a as b, c as d, e"

    In [253]: red
    Out[253]: 0   from some.module import a as b, c as d, e

### Helpers

To reduce the complexity, 2 helpers method are provided:

    In [254]: red = RedBaron("from foo.bar import baz as stuff, plop")

    In [255]: red[0].names()  # names added to the context
    Out[255]: ['stuff', 'plop']

    In [256]: red[0].modules()  # modules imported
    Out[256]: ['baz', 'plop']

    In [257]: red[0].full_path_names()  # names added to the context with full path
    Out[257]: ['foo.bar.stuff', 'foo.bar.plop']

    In [258]: red[0].full_path_modules()  # modules imported with full path
    Out[258]: ['foo.bar.baz', 'foo.bar.plop']

## GeneratorComprehensionNode

A node representing a generator comprehension node.

    In [259]: RedBaron("(x for y in z)")[0].help(deep=True)
    GeneratorComprehensionNode()
      # identifiers: generator_comprehension, generator_comprehension_, generatorcomprehension, generatorcomprehensionnode
      result ->
        NameNode()
          # identifiers: name, name_, namenode
          value='x'
      generators ->
        * ComprehensionLoopNode()
            # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
            iterator ->
              NameNode()
                # identifiers: name, name_, namenode
                value='y'
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='z'
            ifs ->

### SetAttr

    In [260]: red = RedBaron("(x for y in z)")

    In [261]: red
    Out[261]: 0   (x for y in z)

    In [262]: red[0].result = "pouet"

    In [263]: red
    Out[263]: 0   (pouet for y in z)

    In [264]: red[0].generators = "for artichaut in courgette"

    In [265]: red
    Out[265]: 0   (pouet for artichaut in courgette)

## GetitemNode

A node representing a ‘get item’ access on a python object, in other words the ‘[stuff]’ in ‘some_object[stuff]’.

    In [266]: RedBaron("a[b]")[0].value[1].help(deep=True)
    GetitemNode()
      # identifiers: getitem, getitem_, getitemnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

### SetAttr

    In [267]: red = RedBaron("a[b]")

    In [268]: red
    Out[268]: 0   a[b]

    In [269]: red[0].value[1].value = "1 + 1"

    In [270]: red
    Out[270]: 0   a[1 + 1]

## GlobalNode

A node representing a global statement.

    In [271]: RedBaron("global a")[0].help(deep=True)
    GlobalNode()
      # identifiers: global, global_, globalnode
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='a'

### SetAttr

    In [272]: red = RedBaron("global a")

    In [273]: red
    Out[273]: 0   global a

    In [274]: red[0].value = "stuff, plop"

    In [275]: red
    Out[275]: 0   global stuff, plop

## IfNode

A node representing an if statement.

The IfNode, like the ElifNode or the ElseNode, is stored in an IfelseblockNode.

    In [276]: RedBaron("if a: pass")[0].value[0].help(deep=True)
    IfNode()
      # identifiers: if, if_, ifnode
      test ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

IfNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Other attributes work as expected:

    In [277]: red = RedBaron("if a: pass")

    In [278]: red
    Out[278]:
    0   if a: pass

    In [279]: red[0].value[0].test = "1 + 1 == 11"

    In [280]: red
    Out[280]:
    0   if 1 + 1 == 11: pass

## IfelseblockNode

A node representing the conditional block composed of at least one if statement, zero or more elif statements and, at the end, an optional else statement. All those statements are stored in a list.

    In [281]: RedBaron("if a: pass\nelif b: pass\nelse: pass\n")[0].help(deep=True)
    IfelseblockNode()
      # identifiers: ifelseblock, ifelseblock_, ifelseblocknode
      value ->
        * IfNode()
            # identifiers: if, if_, ifnode
            test ->
              NameNode()
                # identifiers: name, name_, namenode
                value='a'
            value ->
              * PassNode()
                  # identifiers: pass, pass_, passnode
        * ElifNode()
            # identifiers: elif, elif_, elifnode
            test ->
              NameNode()
                # identifiers: name, name_, namenode
                value='b'
            value ->
              * PassNode()
                  # identifiers: pass, pass_, passnode
        * ElseNode()
            # identifiers: else, else_, elsenode
            value ->
              * PassNode()
                  # identifiers: pass, pass_, passnode

### SetAttr

Works as expected and is very flexible on its input:

- the input is automatically put at the correct indentation
- the input is automatically right strip
- if the statement is followed, the correct number of blanks lines are added: 2 when at the root of the file, 1 when indented

    In [282]: red = RedBaron("if a: pass\n")

    In [283]: red
    Out[283]:
    0   if a: pass

    In [284]: red[0].value = "if a:\n    pass\nelif b:\n    pass\n\n\n"

    In [285]: red
    Out[285]:
    0   if a:
            pass
        elif b:
            pass

    In [286]: red[0].value = "    if a:\n        pass"

    In [287]: red
    Out[287]:
    0   if a:
            pass

    In [288]: red = RedBaron("if a:\n    pass\n\n\nplop")

    In [289]: red
    Out[289]:
    0   if a:
            pass

    1   plop

    In [290]: red[0].value = "    if a:\n        pass"

    In [291]: red
    Out[291]:
    0   if a:
            pass

    1   plop

    In [292]: red = RedBaron("while True:\n    if plop:\n        break\n\n    stuff")

    In [293]: red
    Out[293]:
    0   while True:
            if plop:
                break

            stuff

    In [294]: red[0].value[1].value = "if a:\n    pass\nelif b:\n    pass\n\n\n"

    In [295]: red
    Out[295]:
    0   while True:
            if plop:
                break

            if a:
            pass
        elif b:
            pass

## ImportNode

A node representing the import statement of the python language.

Be careful, this node and its subnodes are way more complex than what you can expect.

    In [296]: RedBaron("import foo")[0].help(deep=True)
    ImportNode()
      # identifiers: import, import_, importnode
      # helpers: modules, names
      value ->
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target=''
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='foo'

    In [297]: RedBaron("import foo.bar.baz as stuff, another_thing.plop")[0].help(deep=True)
    ImportNode()
      # identifiers: import, import_, importnode
      # helpers: modules, names
      value ->
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target='stuff'
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='foo'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='bar'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='baz'
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target=''
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='another_thing'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='plop'

### SetAttr

Works as expected:

    In [298]: red = RedBaron("import foo")

    In [299]: red[0].value = "foo.bar.baz as plop, stuff, plop.dot"

    In [300]: red
    Out[300]: 0   import foo.bar.baz as plop, stuff, plop.dot

    In [301]: red.help(deep=True)
    0 -----------------------------------------------------
    ImportNode()
      # identifiers: import, import_, importnode
      # helpers: modules, names
      value ->
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target='plop'
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='foo'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='bar'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='baz'
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target=''
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='stuff'
        * DottedAsNameNode()
            # identifiers: dotted_as_name, dotted_as_name_, dottedasname, dottedasnamenode
            target=''
            value ->
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='plop'
              * NameNode()
                  # identifiers: name, name_, namenode
                  value='dot'

### Helpers

To reduce the complexity, 2 helpers method are provided:

    In [302]: red = RedBaron("import foo.bar.baz as stuff, another_thing.plop")

    In [303]: red[0].modules()  # modules imported
    Out[303]: ['foo.bar.baz', 'another_thing.plop']

    In [304]: red[0].names()  # names added to the context
    Out[304]: ['stuff', 'another_thing.plop']

## IntNode

A python integer.

    In [305]: RedBaron("42")[0].help()
    IntNode()
      # identifiers: int, int_, intnode
      value='42'

## KwargsOnlyMarkerNode

New in 0.7.

A node representing the “*” in arguments declaration to force keywords only arguments after itself.

    In [306]: RedBaron("def a(*): pass")[0].arguments[0].help(deep=True)
    KwargsOnlyMarkerNode()
      # identifiers: kwargs_only_marker, kwargs_only_marker_, kwargsonlymarker, kwargsonlymarkernode

## LambdaNode

A node representing a lambda statement.

    In [307]: RedBaron("lambda x: y")[0].help(deep=True)
    LambdaNode()
      # identifiers: lambda, lambda_, lambdanode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='y'
      arguments ->
        * DefArgumentNode()
            # identifiers: def_argument, def_argument_, defargument, defargumentnode
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='x'
            annotation ->
              None
            value ->
              None

### SetAttr

Works as expected:

    In [308]: red = RedBaron("lambda x: y")

    In [309]: red
    Out[309]: 0   lambda x: y

    In [310]: red[0].arguments = "a, b=c, *d, **f"

    In [311]: red
    Out[311]: 0   lambda a, b=c, *d, **f: y

    In [312]: red[0].value = "plop"

    In [313]: red
    Out[313]: 0   lambda a, b=c, *d, **f: plop

## ListArgumentNode

A node representing a “star argument” in a function call or definition.

    In [314]: RedBaron("def a(*b): pass")[0].arguments[0].help(deep=True)
    ListArgumentNode()
      # identifiers: list_argument, list_argument_, listargument, listargumentnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      annotation ->
        None

### SetAttr

Works as expected:

    In [315]: red = RedBaron("def a(*b): pass")

    In [316]: red
    Out[316]:
    0   def a(*b): pass

    In [317]: red[0].arguments[0].value = "plop"

    In [318]: red
    Out[318]:
    0   def a(*plop): pass

New in 0.9

Annotations:

    In [319]: red = RedBaron("def a(*b): pass")

    In [320]: red
    Out[320]:
    0   def a(*b): pass

    In [321]: red[0].arguments[0].annotation = "Int"

    In [322]: red
    Out[322]:
    0   def a(*b : Int): pass

    In [323]: red[0].arguments[0].annotation
    Out[323]: Int

    In [324]: red
    Out[324]:
    0   def a(*b : Int): pass

## ListComprehensionNode

A node representing a list comprehension node.

    In [325]: RedBaron("[x for y in z]")[0].help(deep=True)
    ListComprehensionNode()
      # identifiers: list_comprehension, list_comprehension_, listcomprehension, listcomprehensionnode
      result ->
        NameNode()
          # identifiers: name, name_, namenode
          value='x'
      generators ->
        * ComprehensionLoopNode()
            # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
            iterator ->
              NameNode()
                # identifiers: name, name_, namenode
                value='y'
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='z'
            ifs ->

### SetAttr

    In [326]: red = RedBaron("[x for y in z]")

    In [327]: red
    Out[327]: 0   [x for y in z]

    In [328]: red[0].result = "pouet"

    In [329]: red
    Out[329]: 0   [pouet for y in z]

    In [330]: red[0].generators = "for artichaut in courgette"

    In [331]: red
    Out[331]: 0   [pouet for artichaut in courgette]

## ListNode

A node representing python sugar syntactic notation for list.

    In [332]: RedBaron("[1, 2, 3]")[0].help(deep=True)
    ListNode()
      # identifiers: list, list_, listnode
      value ->
        * IntNode()
            # identifiers: int, int_, intnode
            value='1'
        * IntNode()
            # identifiers: int, int_, intnode
            value='2'
        * IntNode()
            # identifiers: int, int_, intnode
            value='3'

## NameAsNameNode

A node representing an argument to the from import statement.

    In [333]: RedBaron("from x import a as d")[0].targets[0].help(deep=True)
    NameAsNameNode()
      # identifiers: name_as_name, name_as_name_, nameasname, nameasnamenode
      value='a'
      target='d'

### SetAttr

    In [334]: red = RedBaron("from x import a as d")

    In [335]: red
    Out[335]: 0   from x import a as d

    In [336]: red[0].targets[0].value = "some_random_module"

    In [337]: red
    Out[337]: 0   from x import some_random_module as d

    In [338]: red[0].targets[0].target = "stuff"

    In [339]: red
    Out[339]: 0   from x import some_random_module as stuff

## NonlocalNode

New in 0.7.

A node representing a nonlocal statement.

    In [340]: RedBaron("nonlocal a")[0].help(deep=True)
    NonlocalNode()
      # identifiers: nonlocal, nonlocal_, nonlocalnode
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='a'

### SetAttr

    In [341]: red = RedBaron("nonlocal a")

    In [342]: red
    Out[342]: 0   nonlocal a

    In [343]: red[0].value = "stuff, plop"

    In [344]: red
    Out[344]: 0   nonlocal stuff, plop

## PrintNode

A node representing a print statement.

    In [345]: RedBaron("print(stuff)")[0].help(deep=True)
    PrintNode()
      # identifiers: print, print_, printnode
      destination ->
        None
      value ->
        * AssociativeParenthesisNode()
            # identifiers: associative_parenthesis, associative_parenthesis_, associativeparenthesis, associativeparenthesisnode
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='stuff'

### SetAttr

    In [346]: red = RedBaron("print(stuff)")

    In [347]: red
    Out[347]: 0   print(stuff)

    In [348]: red[0].destination = "some_file"

    In [349]: red
    Out[349]: 0   print >>some_file, (stuff)

    In [350]: red[0].value = "a, b, c"

    In [351]: red
    Out[351]: 0   print >>some_file, a, b, c

    In [352]: red[0].destination = ""

    In [353]: red
    Out[353]: 0   print a, b, c

    In [354]: red[0].value = ""

    In [355]: red
    Out[355]: 0   print

## RaiseNode

A node representing a raise statement.

    In [356]: RedBaron("raise Exception(), foo, bar")[0].help(deep=True)
    RaiseNode()
      # identifiers: raise, raise_, raisenode
      comma_or_from=','
      value ->
        AtomtrailersNode()
          # identifiers: atomtrailers, atomtrailers_, atomtrailersnode
          value ->
            * NameNode()
                # identifiers: name, name_, namenode
                value='Exception'
            * CallNode()
                # identifiers: call, call_, callnode
                value ->
      instance ->
        NameNode()
          # identifiers: name, name_, namenode
          value='foo'
      traceback ->
        NameNode()
          # identifiers: name, name_, namenode
          value='bar'

### SetAttr

    In [357]: red = RedBaron("raise stuff")

    In [358]: red
    Out[358]: 0   raise stuff

    In [359]: red[0].value = "foo"

    In [360]: red
    Out[360]: 0   raise foo

    In [361]: red[0].instance = "bar"

    In [362]: red
    Out[362]: 0   raise foo, bar

    In [363]: red[0].traceback = "baz"

    In [364]: red
    Out[364]: 0   raise foo, bar, baz

New in 0.9

How to deal with the “raise from” notation: (by default a comma is inserted to avoid breaking backward compatibility)

    In [365]: red = RedBaron("raise stuff")

    In [366]: red
    Out[366]: 0   raise stuff

    In [367]: red[0].instance = "foo"

    In [368]: red
    Out[368]: 0   raise stuff, foo

    In [369]: red[0].comma_or_from = "from"

    In [370]: red
    Out[370]: 0   raise stuff from foo

    In [371]: red[0].comma_or_from = ","

    In [372]: red
    Out[372]: 0   raise stuff, foo

    In [373]: red[0].instancinstance ""
       .....: red
       .....:
      File "<ipython-input-373-b4a2b0ad37ec>", line 1
        red[0].instancinstance ""
                                ^
    SyntaxError: invalid syntax

    Out[374]: 0   raise stuff, foo

## ReprNode

A node representing python sugar syntactic notation for repr.

    In [375]: RedBaron("`pouet`")[0].help(deep=True)
    ReprNode()
      # identifiers: repr, repr_, reprnode
      value ->
        * NameNode()
            # identifiers: name, name_, namenode
            value='pouet'

## ReturnNode

A node representing a return statement.

    In [376]: RedBaron("return stuff")[0].help(deep=True)
    ReturnNode()
      # identifiers: return, return_, returnnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='stuff'

### SetAttr

    In [377]: red = RedBaron("return stuff")

    In [378]: red
    Out[378]: 0   return stuff

    In [379]: red[0].value = "1 + 1"

    In [380]: red
    Out[380]: 0   return 1 + 1

    In [381]: red[0].value = ""

    In [382]: red
    Out[382]: 0   return

## SetNode

A node representing python sugar syntactic notation for set.

    In [383]: RedBaron("{1, 2, 3}")[0].help(deep=True)
    SetNode()
      # identifiers: set, set_, setnode
      value ->
        * IntNode()
            # identifiers: int, int_, intnode
            value='1'
        * IntNode()
            # identifiers: int, int_, intnode
            value='2'
        * IntNode()
            # identifiers: int, int_, intnode
            value='3'

## SetComprehensionNode

A node representing a set comprehension node.

    In [384]: RedBaron("{x for y in z}")[0].help(deep=True)
    SetComprehensionNode()
      # identifiers: set_comprehension, set_comprehension_, setcomprehension, setcomprehensionnode
      result ->
        NameNode()
          # identifiers: name, name_, namenode
          value='x'
      generators ->
        * ComprehensionLoopNode()
            # identifiers: comprehension_loop, comprehension_loop_, comprehensionloop, comprehensionloopnode
            iterator ->
              NameNode()
                # identifiers: name, name_, namenode
                value='y'
            target ->
              NameNode()
                # identifiers: name, name_, namenode
                value='z'
            ifs ->

### SetAttr

    In [385]: red = RedBaron("{x for y in z}")

    In [386]: red
    Out[386]: 0   {x for y in z}

    In [387]: red[0].result = "pouet"

    In [388]: red
    Out[388]: 0   {pouet for y in z}

    In [389]: red[0].generators = "for artichaut in courgette"

    In [390]: red
    Out[390]: 0   {pouet for artichaut in courgette}

## SliceNode

A node representing a slice, the “1:2:3” that can be found in a GetitemNode.

    In [391]: RedBaron("a[1:-1:2]")[0].value[1].value.help(deep=True)
    SliceNode()
      # identifiers: slice, slice_, slicenode
      has_two_colons=True
      lower ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'
      upper ->
        UnitaryOperatorNode()
          # identifiers: unitary_operator, unitary_operator_, unitaryoperator, unitaryoperatornode
          value='-'
          target ->
            IntNode()
              # identifiers: int, int_, intnode
              value='1'
      step ->
        IntNode()
          # identifiers: int, int_, intnode
          value='2'

### SetAttr

    In [392]: red = RedBaron("a[1:-1:2]")

    In [393]: red
    Out[393]: 0   a[1:-1:2]

    In [394]: red[0].value[1].value.lower = "a"

    In [395]: red
    Out[395]: 0   a[a:-1:2]

    In [396]: red[0].value[1].value.upper = "b"

    In [397]: red
    Out[397]: 0   a[a:b:2]

    In [398]: red[0].value[1].value.step = "stuff"

    In [399]: red
    Out[399]: 0   a[a:b:stuff]

    In [400]: red[0].value[1].value.step = ""

    In [401]: red
    Out[401]: 0   a[a:b]

## SpaceNode

A formatting node representing a space. You’ll probably never have to deal with it except if you play with the way the file is rendered.

Those nodes will be hidden in formatting keys 99% of the time (the only exception is if it’s the last node of the file).

    In [402]: RedBaron("1 + 1")[0].first_formatting[0].help()
    SpaceNode()
      # identifiers: space, space_, spacenode
      value=' '

    In [403]: RedBaron("1 + 1").help()
    0 -----------------------------------------------------
    BinaryOperatorNode()
      # identifiers: binary_operator, binary_operator_, binaryoperator, binaryoperatornode
      value='+'
      first ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'
      second ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'

## StarExpressionNode

New in 0.9

A node representing the result of a deconstruction in an assignment.

    In [404]: red = RedBaron("a, *b = c")

    In [405]: red
    Out[405]: 0   a, *b = c

    In [406]: red[0].target[1].help()
    StarExpressionNode()
      # identifiers: star_expression, star_expression_, starexpression, starexpressionnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

## StringChainNode

This is a special node that handle a particular way of writing a single string in python by putting several strings one after the other while only separated by spaces or endls.

    In [407]: RedBaron("'a' r'b' b'c'")[0].help(deep=True)
    StringChainNode()
      # identifiers: string_chain, string_chain_, stringchain, stringchainnode
      value ->
        * StringNode()
            # identifiers: string, string_, stringnode
            value="'a'"
        * RawStringNode()
            # identifiers: raw_string, raw_string_, rawstring, rawstringnode
            value="r'b'"
        * BinaryStringNode()
            # identifiers: binary_string, binary_string_, binarystring, binarystringnode
            value="b'c'"

### SetAttr

    In [408]: red = RedBaron("'a' r'b' b'c'")

    In [409]: red
    Out[409]: 0   'a' r'b' b'c'

    In [410]: red[0].value = "'plip' 'plop'"

    In [411]: red
    Out[411]: 0   'plip' 'plop'

## TernaryOperatorNode

A node representing the ternary operator expression.

    In [412]: RedBaron("a if b else c")[0].help(deep=True)
    TernaryOperatorNode()
      # identifiers: ternary_operator, ternary_operator_, ternaryoperator, ternaryoperatornode
      first ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'
      second ->
        NameNode()
          # identifiers: name, name_, namenode
          value='c'

### SetAttr

    In [413]: red = RedBaron("a if b else c")

    In [414]: red
    Out[414]: 0   a if b else c

    In [415]: red[0].value = "some_test"

    In [416]: red
    Out[416]: 0   a if some_test else c

    In [417]: red[0].first = "a_value"

    In [418]: red
    Out[418]: 0   a_value if some_test else c

    In [419]: red[0].second = "another_value"

    In [420]: red
    Out[420]: 0   a_value if some_test else another_value

## TryNode

A node representing a try statement. This node is responsible for holding the ExceptNode, FinallyNode and ElseNode.

    In [421]: RedBaron("try: pass\nexcept FooBar: pass\nexcept Exception: pass\nelse: pass\nfinally: pass\n")[0].help(deep=True)
    TryNode()
      # identifiers: try, try_, trynode
      else ->
        ElseNode()
          # identifiers: else, else_, elsenode
          value ->
            * PassNode()
                # identifiers: pass, pass_, passnode
      finally ->
        FinallyNode()
          # identifiers: finally, finally_, finallynode
          value ->
            * PassNode()
                # identifiers: pass, pass_, passnode
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode
      excepts ->
        * ExceptNode()
            # identifiers: except, except_, exceptnode
            delimiter=''
            exception ->
              NameNode()
                # identifiers: name, name_, namenode
                value='FooBar'
            target ->
              None
            value ->
              * PassNode()
                  # identifiers: pass, pass_, passnode
        * ExceptNode()
            # identifiers: except, except_, exceptnode
            delimiter=''
            exception ->
              NameNode()
                # identifiers: name, name_, namenode
                value='Exception'
            target ->
              None
            value ->
              * PassNode()
                  # identifiers: pass, pass_, passnode

### SetAttr

TryNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. For the `else` and the `finally` and the `excepts` attributes, TryNode is very flexible on the range of inputs it can get, like for a CodeBlockNode value’s attribute.

Important: Since `else` and `finally` are reserved keywords in python, you need to append a `_` to those attributes name to access/modify them: `node.else_` and `node.finally_`.

    In [422]: red = RedBaron("try:\n    pass\nexcept:\n    pass\n")

    In [423]: red
    Out[423]:
    0   try:
            pass
        except:
            pass

    In [424]: red[0].else_ = "do_stuff"

    In [425]: red
    Out[425]:
    0   try:
            pass
        except:
            pass
        else:
            do_stuff

    In [426]: red[0].else_ = "else: foobar"

    In [427]: red
    Out[427]:
    0   try:
            pass
        except:
            pass
        else:
            foobar

    In [428]: red[0].else_ = "    else:\n        badly_indented_and_trailing\n\n\n\n"

    In [429]: red
    Out[429]:
    0   try:
            pass
        except:
            pass
        else:
            badly_indented_and_trailing

    # input management of finally_ works the same way than for else_
    In [430]: red[0].finally_ = "close_some_stuff"

    In [431]: red
    Out[431]:
    0   try:
            pass
        except:
            pass
        else:
            badly_indented_and_trailing
        finally:
            close_some_stuff

    In [432]: red[0].else_ = ""

    In [433]: red
    Out[433]:
    0   try:
            pass
        except:
            pass
        finally:
            close_some_stuff

    In [434]: red[0].finally_ = ""

    In [435]: red
    Out[435]:
    0   try:
            pass
        except:
            pass

    In [436]: red[0].excepts = "except A as b:\n    pass"

    In [437]: red
    Out[437]:
    0   try:
            pass
        except A as b:
            pass

    In [438]: red[0].excepts = "except X:\n    pass\nexcept Y:\n    pass"

    In [439]: red
    Out[439]:
    0   try:
            pass
        except X:
            pass
        except Y:
            pass

    # You **CAN'T** do this red[0].excepts = "foobar"

## TupleNode

A node representing python sugar syntactic notation for tuple.

    In [440]: RedBaron("(1, 2, 3)")[0].help(deep=True)
    TupleNode()
      # identifiers: tuple, tuple_, tuplenode
      with_parenthesis=True
      value ->
        * IntNode()
            # identifiers: int, int_, intnode
            value='1'
        * IntNode()
            # identifiers: int, int_, intnode
            value='2'
        * IntNode()
            # identifiers: int, int_, intnode
            value='3'

## UnitaryOperatorNode

A node representing a number sign modification operator like `-2` or `+42`.

    In [441]: RedBaron("-1")[0].help(deep=True)
    UnitaryOperatorNode()
      # identifiers: unitary_operator, unitary_operator_, unitaryoperator, unitaryoperatornode
      value='-'
      target ->
        IntNode()
          # identifiers: int, int_, intnode
          value='1'

### SetAttr

    In [442]: red = RedBaron("-1")

    In [443]: red
    Out[443]: 0   -1

    In [444]: red[0].target = "42"

    In [445]: red
    Out[445]: 0   -42

    In [446]: red[0].value = "+"

    In [447]: red
    Out[447]: 0   +42

## YieldNode

A node representing a yield statement.

    In [448]: RedBaron("yield 42")[0].help(deep=True)
    YieldNode()
      # identifiers: yield, yield_, yieldnode
      value ->
        IntNode()
          # identifiers: int, int_, intnode
          value='42'

### SetAttr

    In [449]: red = RedBaron("yield 42")

    In [450]: red
    Out[450]: 0   yield 42

    In [451]: red[0].value = "stuff"

    In [452]: red
    Out[452]: 0   yield stuff

    In [453]: red[0].value = ""

    In [454]: red
    Out[454]: 0   yield

## YieldAtomNode

A node representing a yield statement surrounded by parenthesis.

    In [455]: RedBaron("(yield 42)")[0].help(deep=True)
    YieldAtomNode()
      # identifiers: yield_atom, yield_atom_, yieldatom, yieldatomnode
      value ->
        IntNode()
          # identifiers: int, int_, intnode
          value='42'

### SetAttr

    In [456]: red = RedBaron("(yield 42)")

    In [457]: red
    Out[457]: 0   (yield 42)

    In [458]: red[0].value = "stuff"

    In [459]: red
    Out[459]: 0   (yield stuff)

    In [460]: red[0].value = ""

    In [461]: red
    Out[461]: 0   (yield)

## YieldFromNode

New in 0.7.

A node representing a “yield from” statement.

    In [462]: RedBaron("yield from 42")[0].help(deep=True)
    YieldFromNode()
      # identifiers: yield_from, yield_from_, yieldfrom, yieldfromnode
      value ->
        IntNode()
          # identifiers: int, int_, intnode
          value='42'

### SetAttr

    In [463]: red = RedBaron("yield from 42")

    In [464]: red
    Out[464]: 0   yield from 42

    In [465]: red[0].value = "stuff"

    In [466]: red
    Out[466]: 0   yield from stuff

## WhileNode

A node representing a while loop.

    In [467]: RedBaron("while condition:\n    pass")[0].help(deep=True)
    WhileNode()
      # identifiers: while, while_, whilenode
      test ->
        NameNode()
          # identifiers: name, name_, namenode
          value='condition'
      else ->
        None
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

WhileNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. The else attributes accept a great ranges of inputs, since `else` is a reserved python keyword, you need to access it using the `else_` attribute. Other attributes work as expected:

    In [468]: red = RedBaron("while condition: pass")

    In [469]: red
    Out[469]:
    0   while condition: pass

    In [470]: red[0].test = "a is not None"

    In [471]: red
    Out[471]:
    0   while a is not None: pass

    In [472]: red[0].else_ = "do_stuff"

    In [473]: red
    Out[473]:
    0   while a is not None: pass
        else:
            do_stuff

    In [474]: red[0].else_ = "else: foobar"

    In [475]: red
    Out[475]:
    0   while a is not None: pass
        else:
            foobar

    In [476]: red[0].else_ = "    else:\n        badly_indented_and_trailing\n\n\n\n"

    In [477]: red
    Out[477]:
    0   while a is not None: pass
        else:
            badly_indented_and_trailing

## WithContext

A node representing a with statement.

    In [478]: RedBaron("with a: pass")[0].help(deep=True)
    WithNode()
      # identifiers: with, with_, withnode
      async=False
      contexts ->
        * WithContextItemNode()
            # identifiers: with_context_item, with_context_item_, withcontextitem, withcontextitemnode
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='a'
            as ->
              None
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

## WithContextItemNode

A node representing one of the context manager items in a with statement.

    In [479]: RedBaron("with a as b: pass")[0].contexts[0].help(deep=True)
    WithContextItemNode()
      # identifiers: with_context_item, with_context_item_, withcontextitem, withcontextitemnode
      value ->
        NameNode()
          # identifiers: name, name_, namenode
          value='a'
      as ->
        NameNode()
          # identifiers: name, name_, namenode
          value='b'

### SetAttr

    In [480]: red = RedBaron("with a: pass")

    In [481]: red
    Out[481]:
    0   with a: pass

    In [482]: red[0].contexts[0].value = "plop"

    In [483]: red
    Out[483]:
    0   with plop: pass

    In [484]: red[0].contexts[0].as_ = "stuff"

    In [485]: red
    Out[485]:
    0   with plop as stuff: pass

    In [486]: red[0].contexts[0].as_ = ""

    In [487]: red
    Out[487]:
    0   with plop: pass

## WithNode

A node representing a with statement.

    In [488]: RedBaron("with a as b, c: pass")[0].help(deep=True)
    WithNode()
      # identifiers: with, with_, withnode
      async=False
      contexts ->
        * WithContextItemNode()
            # identifiers: with_context_item, with_context_item_, withcontextitem, withcontextitemnode
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='a'
            as ->
              NameNode()
                # identifiers: name, name_, namenode
                value='b'
        * WithContextItemNode()
            # identifiers: with_context_item, with_context_item_, withcontextitem, withcontextitemnode
            value ->
              NameNode()
                # identifiers: name, name_, namenode
                value='c'
            as ->
              None
      value ->
        * PassNode()
            # identifiers: pass, pass_, passnode

### SetAttr

WithNode is a CodeBlockNode which means its value attribute accepts a wide range of values, see CodeBlockNode for more information. Other attributes work as expected:

    In [489]: red = RedBaron("with a: pass")

    In [490]: red
    Out[490]:
    0   with a: pass

    In [491]: red[0].contexts = "b as plop, stuff()"

    In [492]: red
    Out[492]:
    0   with b as plop, stuff(): pass

New in 0.8.

Async is a boolean attribute that determine if a function is async:

    In [493]: red =  RedBaron("with a as b: pass")

    In [494]: red[0].async_
    Out[494]: False

    In [495]: red[0].async_ = True

    In [496]: red
    Out[496]:
    0   async with a as b: pass

    In [497]: red[0].async_ = False

    In [498]: red
    Out[498]:
    0   with a as b: pass

Warning

As of python 3.7 async and await are now reserved keywords so don’t uses red.async, it works as expected but won’t make your code forward compatible.