Can't unparse code wiht dict unpacking
nvbn opened this issue · 1 comments
nvbn commented
When I'm trying to unparse ast with dict unpacking it fails with:
unparse(ast.parse('{1: 1, **x}'))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-d010b38dd24f> in <module>()
----> 1 unparse(ast.parse('{1: 1, **x}'))
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/__init__.py in unparse(tree)
11 def unparse(tree):
12 v = cStringIO()
---> 13 Unparser(tree, file=v)
14 return v.getvalue()
15
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in __init__(self, tree, file)
36 self.future_imports = []
37 self._indent = 0
---> 38 self.dispatch(tree)
39 print("", file=self.f)
40 self.f.flush()
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in dispatch(self, tree)
64 return
65 meth = getattr(self, "_"+tree.__class__.__name__)
---> 66 meth(tree)
67
68
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in _Module(self, tree)
76 def _Module(self, tree):
77 for stmt in tree.body:
---> 78 self.dispatch(stmt)
79
80 def _Interactive(self, tree):
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in dispatch(self, tree)
64 return
65 meth = getattr(self, "_"+tree.__class__.__name__)
---> 66 meth(tree)
67
68
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in _Expr(self, tree)
88 def _Expr(self, tree):
89 self.fill()
---> 90 self.dispatch(tree.value)
91
92 def _Import(self, t):
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in dispatch(self, tree)
64 return
65 meth = getattr(self, "_"+tree.__class__.__name__)
---> 66 meth(tree)
67
68
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in _Dict(self, t)
565 self.write(": ")
566 self.dispatch(v)
--> 567 interleave(lambda: self.write(", "), write_pair, zip(t.keys, t.values))
568 self.write("}")
569
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in interleave(inter, f, seq)
23 for x in seq:
24 inter()
---> 25 f(x)
26
27 class Unparser:
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in write_pair(pair)
562 def write_pair(pair):
563 (k, v) = pair
--> 564 self.dispatch(k)
565 self.write(": ")
566 self.dispatch(v)
/home/nvbn/miniconda3/lib/python3.6/site-packages/astunparse/unparser.py in dispatch(self, tree)
63 self.dispatch(t)
64 return
---> 65 meth = getattr(self, "_"+tree.__class__.__name__)
66 meth(tree)
67
AttributeError: 'Unparser' object has no attribute '_NoneType'
simonpercivall commented
This is (should now be) fixed in v1.6.0. (Please reopen if I missed something.)