1
0
forked from VimPlug/jedi

Implement all remaining Path issues and use it instead of strings

This commit is contained in:
Dave Halter
2020-07-12 01:14:00 +02:00
parent db0e90763b
commit 480a464179
23 changed files with 131 additions and 97 deletions
+8 -7
View File
@@ -2,6 +2,7 @@ import os
import re
from functools import wraps
from collections import namedtuple
from pathlib import Path
from jedi import settings
from jedi.file_io import FileIO
@@ -11,10 +12,10 @@ from jedi.inference.base_value import ValueSet, NO_VALUES
from jedi.inference.gradual.stub_value import TypingModuleWrapper, StubModuleValue
from jedi.inference.value import ModuleValue
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
DJANGO_INIT_PATH = os.path.join(_jedi_path, 'third_party', 'django-stubs',
'django-stubs', '__init__.pyi')
_jedi_path = Path(__file__).parent.parent.parent
TYPESHED_PATH = _jedi_path.joinpath('third_party', 'typeshed')
DJANGO_INIT_PATH = _jedi_path.joinpath('third_party', 'django-stubs',
'django-stubs', '__init__.pyi')
_IMPORT_MAP = dict(
_collections='collections',
@@ -60,7 +61,7 @@ def _create_stub_map(directory_path_info):
def _get_typeshed_directories(version_info):
check_version_list = ['2and3', '3']
for base in ['stdlib', 'third_party']:
base_path = os.path.join(TYPESHED_PATH, base)
base_path = TYPESHED_PATH.joinpath(base)
base_list = os.listdir(base_path)
for base_list_entry in base_list:
match = re.match(r'(\d+)\.(\d+)$', base_list_entry)
@@ -70,7 +71,7 @@ def _get_typeshed_directories(version_info):
for check_version in check_version_list:
is_third_party = base != 'stdlib'
yield PathInfo(os.path.join(base_path, check_version), is_third_party)
yield PathInfo(str(base_path.joinpath(check_version)), is_third_party)
_version_cache = {}
@@ -181,7 +182,7 @@ def _try_to_load_stub(inference_state, import_names, python_value_set,
return _try_to_load_stub_from_file(
inference_state,
python_value_set,
file_io=FileIO(DJANGO_INIT_PATH),
file_io=FileIO(str(DJANGO_INIT_PATH)),
import_names=import_names,
)
+12 -7
View File
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from jedi.inference.gradual.typeshed import TYPESHED_PATH, create_stub_module
@@ -9,14 +10,18 @@ def load_proper_stub_module(inference_state, file_io, import_names, module_node)
module.
"""
path = file_io.path
assert path.endswith('.pyi')
if path.startswith(TYPESHED_PATH):
# /foo/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
rest = path[len(TYPESHED_PATH) + 1: -4]
split_paths = tuple(rest.split(os.path.sep))
path = Path(path)
assert path.suffix == '.pyi'
try:
relative_path = path.relative_to(TYPESHED_PATH)
except ValueError:
pass
else:
# /[...]/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
rest = relative_path.with_suffix('')
# Remove the stdlib/3 or third_party/3.6 part
import_names = split_paths[2:]
if import_names[-1] == '__init__':
import_names = rest.parts[2:]
if rest.name == '__init__':
import_names = import_names[:-1]
if import_names is not None: