Giter VIP home page Giter VIP logo

Comments (7)

williamjamir avatar williamjamir commented on July 28, 2024 1

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.

soupytwist avatar soupytwist commented on July 28, 2024

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.

williamjamir avatar williamjamir commented on July 28, 2024

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.

soupytwist avatar soupytwist commented on July 28, 2024

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.

soupytwist avatar soupytwist commented on July 28, 2024

It seems I was too hasty.

from pasta.

williamjamir avatar williamjamir commented on July 28, 2024

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.

soupytwist avatar soupytwist commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.