If newer versions are using Jedi (e.g. at the moment Python 3.7), it shouldn't just result in a grammar issue, just because that grammar doesn't not exist. Just take the Python 3.6 grammar instead.

This commit is contained in:
Dave Halter
2017-01-07 15:54:04 +01:00
parent aff3950085
commit 6d00a5702f
3 changed files with 21 additions and 2 deletions

View File

@@ -233,6 +233,11 @@ try:
except ImportError: except ImportError:
from itertools import izip_longest as zip_longest # Python 2 from itertools import izip_longest as zip_longest # Python 2
try:
FileNotFoundError = FileNotFoundError
except NameError:
FileNotFoundError = IOError
def no_unicode_pprint(dct): def no_unicode_pprint(dct):
""" """

View File

@@ -18,6 +18,7 @@ complexity of the ``Parser`` (there's another parser sitting inside
import os import os
import re import re
from jedi._compatibility import FileNotFoundError
from jedi.parser import tree as pt from jedi.parser import tree as pt
from jedi.parser import tokenize from jedi.parser import tokenize
from jedi.parser.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER, from jedi.parser.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER,
@@ -40,7 +41,7 @@ class ParseError(Exception):
""" """
def load_grammar(version='3.4'): def load_grammar(version='3.6'):
# For now we only support two different Python syntax versions: The latest # For now we only support two different Python syntax versions: The latest
# Python 3 and Python 2. This may change. # Python 3 and Python 2. This may change.
if version in ('3.2', '3.3'): if version in ('3.2', '3.3'):
@@ -55,7 +56,11 @@ def load_grammar(version='3.4'):
try: try:
return _loaded_grammars[path] return _loaded_grammars[path]
except KeyError: except KeyError:
try:
return _loaded_grammars.setdefault(path, generate_grammar(path)) return _loaded_grammars.setdefault(path, generate_grammar(path))
except FileNotFoundError:
# Just load the default if the file does not exist.
return load_grammar()
class ParserSyntaxError(object): class ParserSyntaxError(object):

View File

@@ -234,3 +234,12 @@ def test_python3_octal():
assert module.children[0].children[0].type == 'number' assert module.children[0].children[0].type == 'number'
else: else:
assert module.children[0].type == 'error_node' assert module.children[0].type == 'error_node'
def test_load_newer_grammar():
# This version shouldn't be out for a while, but if we somehow get this it
# should just take the latest Python grammar.
load_grammar('15.8')
# The same is true for very old grammars (even though this is probably not
# going to be an issue.
load_grammar('1.5')