Make an Attribute or Name node for name. Translate a qualified name into nested Attribute nodes (and a Name node). Args: name: The name to translate to a node. ctx: What context this name is used in. Defaults to Load() Returns: A Name or Attribute node.
(name, ctx=ast.Load())
| 45 | |
| 46 | |
| 47 | def full_name_node(name, ctx=ast.Load()): |
| 48 | """Make an Attribute or Name node for name. |
| 49 | |
| 50 | Translate a qualified name into nested Attribute nodes (and a Name node). |
| 51 | |
| 52 | Args: |
| 53 | name: The name to translate to a node. |
| 54 | ctx: What context this name is used in. Defaults to Load() |
| 55 | |
| 56 | Returns: |
| 57 | A Name or Attribute node. |
| 58 | """ |
| 59 | names = name.split(".") |
| 60 | names.reverse() |
| 61 | node = ast.Name(id=names.pop(), ctx=ast.Load()) |
| 62 | while names: |
| 63 | node = ast.Attribute(value=node, attr=names.pop(), ctx=ast.Load()) |
| 64 | |
| 65 | # Change outermost ctx to the one given to us (inner ones should be Load). |
| 66 | node.ctx = ctx |
| 67 | return node |
| 68 | |
| 69 | |
| 70 | def get_arg_value(node, arg_name, arg_pos=None): |