diff options
author | Azeem Bande-Ali <A.BandeAli@gmail.com> | 2019-01-28 09:30:34 -0500 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-01-28 15:30:34 +0100 |
commit | 67bec180dc9ffd954ea2fb0e8f9f5f4993665d02 (patch) | |
tree | 2c6ad2b78ac34fff97dd9d7e61a240309ce3ddd7 /doc | |
parent | 67c590ccc22dcec516e54e04a3bf9ebfc1bff42f (diff) | |
download | astroid-git-67bec180dc9ffd954ea2fb0e8f9f5f4993665d02.tar.gz |
Docs: Fixing transformation example to be functional (#640)
The previous example was referencing undefined variables and returning the wrong node.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/extending.rst | 18 |
1 files 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, |