diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 5004a7a2..4710e253 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -233,6 +233,11 @@ try: except ImportError: from itertools import izip_longest as zip_longest # Python 2 +try: + FileNotFoundError = FileNotFoundError +except NameError: + FileNotFoundError = IOError + def no_unicode_pprint(dct): """ diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 492ca222..c411e878 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -18,6 +18,7 @@ complexity of the ``Parser`` (there's another parser sitting inside import os import re +from jedi._compatibility import FileNotFoundError from jedi.parser import tree as pt from jedi.parser import tokenize 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 # Python 3 and Python 2. This may change. if version in ('3.2', '3.3'): @@ -55,7 +56,11 @@ def load_grammar(version='3.4'): try: return _loaded_grammars[path] except KeyError: - return _loaded_grammars.setdefault(path, generate_grammar(path)) + try: + 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): diff --git a/test/test_parser/test_parser.py b/test/test_parser/test_parser.py index 14ec763a..09125498 100644 --- a/test/test_parser/test_parser.py +++ b/test/test_parser/test_parser.py @@ -234,3 +234,12 @@ def test_python3_octal(): assert module.children[0].children[0].type == 'number' else: 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')