diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-06 01:22:55 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-06 01:22:55 +0300 |
commit | 7fe6eb2afac0abb1aae04414c1fb3c69df79ad8b (patch) | |
tree | 1050881bf66e3fed26b3ea5c9a502a4547c2a60d /astroid/as_string.py | |
parent | 5f8ddec3d362056d603efbf097f588d1da52c73a (diff) | |
download | astroid-7fe6eb2afac0abb1aae04414c1fb3c69df79ad8b.tar.gz |
Add a new node, DictUnpack, for representing the unpacking of a dict using PEP 448
This is a different approach than what the builtin ast module does,
since it just uses None to represent this kind of operation,
which seems conceptually wrong, due to the fact the AST contains
non-AST nodes. Closes issue #206.
Diffstat (limited to 'astroid/as_string.py')
-rw-r--r-- | astroid/as_string.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py index 20f4936..14ef45f 100644 --- a/astroid/as_string.py +++ b/astroid/as_string.py @@ -159,9 +159,20 @@ class AsStringVisitor(object): def visit_dict(self, node): """return an astroid.Dict node as string""" - return '{%s}' % ', '.join(['%s: %s' % (key.accept(self), - value.accept(self)) - for key, value in node.items]) + return '{%s}' % ', '.join(self._visit_dict(node)) + + def _visit_dict(self, node): + for key, value in node.items: + key = key.accept(self) + value = value.accept(self) + if key == '**': + # It can only be a DictUnpack node. + yield key + value + else: + yield '%s: %s' % (key, value) + + def visit_dictunpack(self, node): + return '**' def visit_dictcomp(self, node): """return an astroid.DictComp node as string""" |