From 67bec180dc9ffd954ea2fb0e8f9f5f4993665d02 Mon Sep 17 00:00:00 2001 From: Azeem Bande-Ali Date: Mon, 28 Jan 2019 09:30:34 -0500 Subject: Docs: Fixing transformation example to be functional (#640) The previous example was referencing undefined variables and returning the wrong node. --- doc/extending.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/extending.rst b/doc/extending.rst index 9f9e7b80..ab80115a 100644 --- a/doc/extending.rst +++ b/doc/extending.rst @@ -115,20 +115,20 @@ Now, with this knowledge, let's see how our transform might look:: lineno=node.lineno, col_offset=node.col_offset, parent=node.parent, - ) - formatted_value_node = astroid.FormattedValue( + ) + formatted_value_node = astroid.FormattedValue( lineno=node.lineno, col_offset=node.col_offset, parent=node.parent, - ) - new_node.postinit(value=node.args[0]) + ) + formatted_value_node.postinit(value=node.args[0]) - # Need to extract the part of the string that doesn't - # have the formatting placeholders - string = extract_string_without_placeholder(node.func.expr) + # Removes the {} since it will be represented as + # formatted_value_node + string = astroid.Const(node.func.expr.value.replace('{}', '')) - f_string_node.postinit(values=[string, f_string_node]) - return new_node + f_string_node.postinit(values=[string, formatted_value_node]) + return f_string_node astroid.MANAGER.register_transform( astroid.Call, -- cgit v1.2.1