Comments (7)
Just out of curiosity (I know it will not interfere with this problem), this different behavior occurred in the transition from Python 2.7.8 to 2.7.9
Checking the changelog I found this:
- Issue #21591: Correctly handle qualified exec statements in tuple form by moving compatibility layer from run-time to AST transformation.
from pasta.
Hmm. So the parsed AST from this is:
"Module(body=[Exec(body=Tuple(elts=[Str(s='x = 10'), Dict(keys=[], values=[])], ctx=Load()), globals=None, locals=None)])"
I can't reproduce it on python 2.7.6:
import pasta
t = pasta.parse("exec('x = 10' , {} )")
It shouldn't be expecting "in" unless the ast parses out something for globals
. What's your python version? Can you provide the output of:
import ast
ast.dump(ast.parse("exec('x = 10' , {} )"))
from pasta.
I'm using Python 2.7.14
Below you can check the output requested
$ python
Python 2.7.14 | packaged by conda-forge | (default, Dec 25 2017, 01:16:05)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.dump(ast.parse("exec('x = 10' , {} )"))
"Module(body=[Exec(body=Str(s='x = 10'), globals=Dict(keys=[], values=[]), locals=None)])"
from pasta.
Okay, that explains it anyway :)
Looks like some change in the parser, so I'll have to account for both. Thanks for reporting it!
from pasta.
It seems I was too hasty.
from pasta.
Executing the code available on the master I found this issue with exec too.
Executing against a single line with exec it's ok:
exec('cmd', {})
But when I added something after the exec, the parse breaks =/
exec('cmd', {})
print()
Error:
pasta.base.annotate.AnnotationError: Expected 'print' but found ')'
line 1: exec('cmd', {})
Full Stack
Traceback (most recent call last):
File "script.py", line 6, in <module>
tree = pasta.parse(file.read())
File "w:\william\repo_pasta\pasta\__init__.py", line 25, in parse
annotator.visit(t)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 1048, in visit
super(AstAnnotator, self).visit(node)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "W:\alfasim\envs\test_pasta\lib\ast.py", line 241, in visit
return visitor(node)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 79, in wrapped
f(self, node, *args, **kwargs)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 168, in visit_Module
self.generic_visit(node)
File "W:\alfasim\envs\test_pasta\lib\ast.py", line 249, in generic_visit
self.visit(item)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 1048, in visit
super(AstAnnotator, self).visit(node)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 115, in visit
super(BaseVisitor, self).visit(node)
File "W:\alfasim\envs\test_pasta\lib\ast.py", line 241, in visit
return visitor(node)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 43, in wrapped
f(self, node, *args, **kwargs)
File "w:\william\repo_pasta\pasta\base\annotate.py", line 575, in visit_Print
self.attr(node, 'print_open', ['print', self.ws], default='print ')
File "w:\william\repo_pasta\pasta\base\annotate.py", line 1173, in attr
attr_parts.append(self.token(attr_val))
File "w:\william\repo_pasta\pasta\base\annotate.py", line 1106, in token
token_val, token.src, token.start[0], token.line))
pasta.base.annotate.AnnotationError: Expected 'print' but found ')'
line 1: exec('cmd', {})
from pasta.
Yes, I see the problem. I'll need a more generic solution for this, it might also affect a few other places.
Generally, there needs to be support for when multiple children of a node can be parenthesized. Thanks for following up on it. I'll start working on this when I get a chance.
from pasta.
Related Issues (20)
- Python 3.10 support HOT 3
- Default formatting Subscript slice is inconsistent in python3.9+
- Support for with statement with multiple arguments
- Support for 'nonlocal' keywords
- Colgate
- f-strings over multiple lines HOT 4
- Auto-detect indentation in a file and reuse on unformatted code
- Support mixing tabs and spaces in python2 HOT 1
- Lacking test covered in codegen_test.py
- Bad indentation when rewriting funcion body (new bug) HOT 3
- Bad indentation when using try..finally HOT 2
- Fails to parse usages of metaclass HOT 3
- Support formatting-preserving insertion into collections
- IndentationError when appending new node to function body HOT 3
- Support for async code HOT 1
- Extend scope.analyze to support PEP 484 forward references
- CI doesn't works
- Some tests are broken HOT 1
- MIgrate from setuptools test to tox
- Incorrect rename behavior
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pasta.