diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index a7a53bdc..13c1975c 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -339,6 +339,13 @@ try: except NameError: PermissionError = IOError +try: + NotADirectoryError = NotADirectoryError +except NameError: + class NotADirectoryError(Exception): + # Don't implement this for Python 2 anymore. + pass + def no_unicode_pprint(dct): """ diff --git a/jedi/api/project.py b/jedi/api/project.py index 005d6827..e01a87a3 100644 --- a/jedi/api/project.py +++ b/jedi/api/project.py @@ -13,7 +13,7 @@ import json import sys from jedi._compatibility import FileNotFoundError, PermissionError, \ - IsADirectoryError + IsADirectoryError, NotADirectoryError from jedi import debug from jedi.api.environment import get_cached_default_environment, create_environment from jedi.api.exceptions import WrongVersion @@ -383,6 +383,8 @@ def get_default_project(path=None): return Project.load(dir) except (FileNotFoundError, IsADirectoryError, PermissionError): pass + except NotADirectoryError: + continue if first_no_init_file is None: if os.path.exists(os.path.join(dir, '__init__.py')): diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index c21579a5..48e83378 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -20,6 +20,12 @@ def test_django_default_project(Script): assert script._inference_state.project._django is True +def test_django_default_project_of_file(Script): + project = get_default_project(__file__) + d = os.path.dirname + assert project._path == d(d(d(__file__))) + + def test_interpreter_project_path(): # Run from anywhere it should be the cwd. dir = os.path.join(root_dir, 'test')