Return the extracted and converted value of a node or None
(node, body)
| 114 | |
| 115 | |
| 116 | def node_to_value(node, body): |
| 117 | """ |
| 118 | Return the extracted and converted value of a node or None |
| 119 | """ |
| 120 | if node is None: |
| 121 | return |
| 122 | |
| 123 | if isinstance(node, ast.Constant): |
| 124 | return node.value |
| 125 | |
| 126 | if isinstance(node, (ast.List, ast.Tuple, ast.Set,)): |
| 127 | return [node_to_value(subnode, body) for subnode in node.elts] |
| 128 | |
| 129 | if isinstance(node, ast.Dict): |
| 130 | result = {} |
| 131 | for key, value in zip(node.keys, node.values): |
| 132 | result[node_to_value(key, body)] = node_to_value(value, body) |
| 133 | return result |
| 134 | |
| 135 | if isinstance(node, ast.Name): |
| 136 | variable = find_variable_in_body(body, node.id) |
| 137 | if variable is not None: |
| 138 | return node_to_value(variable, body) |
| 139 | |
| 140 | if isinstance(node, ast.Call): |
| 141 | if not isinstance(node.func, ast.Name): |
| 142 | return |
| 143 | if node.func.id != 'dict': |
| 144 | return |
| 145 | return get_call_kwargs(node, body) |
| 146 | return |
| 147 | |
| 148 | |
| 149 | def find_variable_in_body(body, name): |
no test coverage detected