Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to recognize trailing comma on import statement with parenthese #24

Closed
williamjamir opened this issue Jan 17, 2018 · 1 comment
Closed

Comments

@williamjamir
Copy link
Contributor

williamjamir commented Jan 17, 2018

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
Copy link
Collaborator

Thanks for finding and reporting all these corner cases :)

This can probably be added to a generalized function as well.

soupytwist added a commit that referenced this issue Jan 22, 2018
Fixes #24.

Some statements can have parenthesized parts within them that are more
than a single sub-expression, and these may also have a trailing comma.
To handle these cases, I'm generalizing the "scope" function again to
include a trailing comma optionally.
soupytwist added a commit that referenced this issue Jan 22, 2018
Fixes #24.

Some statements can have parenthesized parts within them that are more
than a single sub-expression, and these may also have a trailing comma.
To handle these cases, I'm generalizing the "scope" function again to
include a trailing comma optionally.
soupytwist added a commit that referenced this issue Jan 23, 2018
…#28)

Handle parenthesized parts of statements with optional trailing comma

Fixes #24.

Some statements can have parenthesized parts within them that are more
than a single sub-expression, and these may also have a trailing comma.
To handle these cases, I'm generalizing the "scope" function again to
include a trailing comma optionally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants