Failed to recognize trailing comma on import statement with parenthese
williamjamir opened this issue · 1 comments
williamjamir commented
Hi,
Trailing comma is not allowed in import, but when inside parentheses it's valid syntax
I know that this one can sound too specific, but still a valid syntax =)
file:
from foo.a import (do,)
do()
Script:
import pasta
from pasta.augment import rename
path = r'test.py'
with open(path) as file:
tree = pasta.parse(file.read())
Full stack trace
Traceback (most recent call last):
File "script.py", line 8, in <module>
tree = pasta.parse(file.read())
File "/opt/pasta/pasta/__init__.py", line 25, in parse
annotator.visit(t)
File "/opt/pasta/pasta/base/annotate.py", line 1055, in visit
super(AstAnnotator, self).visit(node)
File "/opt/pasta/pasta/base/annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "/home/william/miniconda3/envs/google_pasta_py27/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/opt/pasta/pasta/base/annotate.py", line 79, in wrapped
f(self, node, *args, **kwargs)
File "/opt/pasta/pasta/base/annotate.py", line 168, in visit_Module
self.generic_visit(node)
File "/home/william/miniconda3/envs/google_pasta_py27/lib/python2.7/ast.py", line 249, in generic_visit
self.visit(item)
File "/opt/pasta/pasta/base/annotate.py", line 1055, in visit
super(AstAnnotator, self).visit(node)
File "/opt/pasta/pasta/base/annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "/home/william/miniconda3/envs/google_pasta_py27/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/opt/pasta/pasta/base/annotate.py", line 43, in wrapped
f(self, node, *args, **kwargs)
File "/opt/pasta/pasta/base/annotate.py", line 520, in visit_Expr
self.visit(node.value)
File "/opt/pasta/pasta/base/annotate.py", line 1055, in visit
super(AstAnnotator, self).visit(node)
File "/opt/pasta/pasta/base/annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "/home/william/miniconda3/envs/google_pasta_py27/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/opt/pasta/pasta/base/annotate.py", line 43, in wrapped
f(self, node, *args, **kwargs)
File "/opt/pasta/pasta/base/annotate.py", line 637, in visit_Call
self.visit(node.func)
File "/opt/pasta/pasta/base/annotate.py", line 1055, in visit
super(AstAnnotator, self).visit(node)
File "/opt/pasta/pasta/base/annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "/home/william/miniconda3/envs/google_pasta_py27/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/opt/pasta/pasta/base/annotate.py", line 43, in wrapped
f(self, node, *args, **kwargs)
File "/opt/pasta/pasta/base/annotate.py", line 754, in visit_Name
self.token(node.id)
File "/opt/pasta/pasta/base/annotate.py", line 1118, in token
token_val, token.src, token.start[0], token.line))
pasta.base.annotate.AnnotationError: Expected 'do' but found ','
line 1: from foo.a import (do,)
cc @nicoddemus
soupytwist commented
Thanks for finding and reporting all these corner cases :)
This can probably be added to a generalized function as well.