diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-02-01 11:53:36 +0000 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-02-13 14:08:58 +0000 |
commit | 6d2529632bae545ff7564501cac14316d5ea9204 (patch) | |
tree | cfcb11c01f1ddd4806a24469687a1ebc18bd41f4 /astroid/test_utils.py | |
parent | 18fa724c04c2393b134d57d4fe4cebe38472bad8 (diff) | |
download | astroid-git-6d2529632bae545ff7564501cac14316d5ea9204.tar.gz |
Changed the way how parameters are being built
The old way consisted in having the parameter names, their
defaults and their annotations separated in different components
of the Arguments node. We introduced a new Param node, which holds
the name of a parameter, its default value and its annotation.
If any of the last two values are missing, then that slot will be
filled with a new node kind, Empty, which is used for specifying the
lack of something (None could have been used instead, but that means having
non-AST nodes in the Arguments node).
We're also having support for positional only arguments, for the moment
only in raw_building.
Close #215
Diffstat (limited to 'astroid/test_utils.py')
-rw-r--r-- | astroid/test_utils.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/astroid/test_utils.py b/astroid/test_utils.py index b15ab766..ff81cd59 100644 --- a/astroid/test_utils.py +++ b/astroid/test_utils.py @@ -19,6 +19,7 @@ _TRANSIENT_FUNCTION = '__' # when calling extract_node. _STATEMENT_SELECTOR = '#@' + def _extract_expressions(node): """Find expressions in a call to _TRANSIENT_FUNCTION and extract them. @@ -46,8 +47,18 @@ def _extract_expressions(node): child = getattr(node.parent, name) if isinstance(child, (list, tuple)): for idx, compound_child in enumerate(child): - if compound_child is node: + + # Can't find a cleaner way to do this. + if isinstance(compound_child, nodes.Parameter): + if compound_child.default is node: + child[idx].default = real_expr + elif compound_child.annotation is node: + child[idx].annotation = real_expr + else: + child[idx] = real_expr + elif compound_child is node: child[idx] = real_expr + elif child is node: setattr(node.parent, name, real_expr) yield real_expr |