bblfsh / python-driver

GNU General Public License v3.0
10 stars 16 forks source link

Exception in function annotations #200

Open chess-equality opened 5 years ago

chess-equality commented 5 years ago

I have the following function:

def function8(param: 'int'):
    print "functionAnnotation"

Parsing this with the BblfshClient results in the following exception:

ParseResponse(FATAL,Vector(syntax error: Errors produced trying to get an AST for both Python versions
------ Python2 errors:
[b'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\n  File "/opt/driver/bin/.local/lib/python3.6/site-packages/pydetector/ast2dict.py", line 19, in ast2dict\n    return visitor.parse()\n  File "/opt/driver/bin/.local/lib/python3.6/site-packages/pydetector/ast2dict.py", line 45, in parse\n    tree = ast.parse(self.codestr, mode=\'exec\')\n  File "/usr/lib/python2.7/ast.py", line 37, in parse\n    return compile(source, filename, mode, PyCF_ONLY_AST)\n  File "<unknown>", line 22\n    def function8(param: \'int\'):\n                       ^\nSyntaxError: invalid syntax\n']
------ Python3 errors:
['Traceback (most recent call last):\n  File "/opt/driver/bin/.local/lib/python3.6/site-packages/pydetector/ast_checks.py", line 53, in check_ast\n    current_ast = ast2dict(code)\n  File "/opt/driver/bin/.local/lib/python3.6/site-packages/pydetector/ast2dict.py", line 19, in ast2dict\n    return visitor.parse()\n  File "/opt/driver/bin/.local/lib/python3.6/site-packages/pydetector/ast2dict.py", line 45, in parse\n    tree = ast.parse(self.codestr, mode=\'exec\')\n  File "/usr/local/lib/python3.6/ast.py", line 35, in parse\n    return compile(source, filename, mode, PyCF_ONLY_AST)\n  File "<unknown>", line 2\n    print ""\n           ^\nSyntaxError: Missing parentheses in call to \'print\'. Did you mean print("")?\n']),Some(Duration(0,24164502)),None,python,)
dennwc commented 5 years ago

Sorry for the late response, but we need more information on this one.

The problem is that print x is Python 2 syntax (as opposed to print(x) in Python 3).

At the same time the annotation syntax (param: 'int') is invalid in Python 2 as far as I'm aware.

The question is, have you seen those files in the wild? Or was it an example to test Babelfish?