forked from VimPlug/jedi
Get rid of cast_path
This commit is contained in:
@@ -7,22 +7,6 @@ import sys
|
|||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
def cast_path(string):
|
|
||||||
"""
|
|
||||||
Take a bytes or str path and cast it to unicode.
|
|
||||||
|
|
||||||
Apparently it is perfectly fine to pass both byte and unicode objects into
|
|
||||||
the sys.path. This probably means that byte paths are normal at other
|
|
||||||
places as well.
|
|
||||||
|
|
||||||
Since this just really complicates everything and Python 2.7 will be EOL
|
|
||||||
soon anyway, just go with always strings.
|
|
||||||
"""
|
|
||||||
if isinstance(string, bytes):
|
|
||||||
return str(string, encoding='UTF-8', errors='replace')
|
|
||||||
return str(string)
|
|
||||||
|
|
||||||
|
|
||||||
def pickle_load(file):
|
def pickle_load(file):
|
||||||
try:
|
try:
|
||||||
return pickle.load(file)
|
return pickle.load(file)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from pathlib import Path
|
|||||||
from zipimport import zipimporter
|
from zipimport import zipimporter
|
||||||
from importlib.machinery import all_suffixes
|
from importlib.machinery import all_suffixes
|
||||||
|
|
||||||
from jedi._compatibility import cast_path
|
|
||||||
from jedi.inference.compiled import access
|
from jedi.inference.compiled import access
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import parser_utils
|
from jedi import parser_utils
|
||||||
@@ -15,7 +14,7 @@ from jedi.file_io import KnownContentFileIO, ZipFileIO
|
|||||||
|
|
||||||
|
|
||||||
def get_sys_path():
|
def get_sys_path():
|
||||||
return list(map(cast_path, sys.path))
|
return sys.path
|
||||||
|
|
||||||
|
|
||||||
def load_module(inference_state, **kwargs):
|
def load_module(inference_state, **kwargs):
|
||||||
@@ -190,7 +189,7 @@ def _from_loader(loader, string):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None, is_package
|
return None, is_package
|
||||||
else:
|
else:
|
||||||
module_path = cast_path(get_filename(string))
|
module_path = get_filename(string)
|
||||||
|
|
||||||
# To avoid unicode and read bytes, "overwrite" loader.get_source if
|
# To avoid unicode and read bytes, "overwrite" loader.get_source if
|
||||||
# possible.
|
# possible.
|
||||||
@@ -212,7 +211,7 @@ def _from_loader(loader, string):
|
|||||||
if code is None:
|
if code is None:
|
||||||
return None, is_package
|
return None, is_package
|
||||||
if isinstance(loader, zipimporter):
|
if isinstance(loader, zipimporter):
|
||||||
return ZipFileIO(module_path, code, Path(cast_path(loader.archive))), is_package
|
return ZipFileIO(module_path, code, Path(loader.archive)), is_package
|
||||||
|
|
||||||
return KnownContentFileIO(module_path, code), is_package
|
return KnownContentFileIO(module_path, code), is_package
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from pathlib import Path
|
|||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.inference.utils import to_list
|
from jedi.inference.utils import to_list
|
||||||
from jedi._compatibility import cast_path
|
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.inference.filters import AbstractFilter
|
from jedi.inference.filters import AbstractFilter
|
||||||
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
||||||
@@ -293,10 +292,7 @@ class CompiledModule(CompiledValue):
|
|||||||
return CompiledModuleContext(self)
|
return CompiledModuleContext(self)
|
||||||
|
|
||||||
def py__path__(self):
|
def py__path__(self):
|
||||||
paths = self.access_handle.py__path__()
|
return self.access_handle.py__path__()
|
||||||
if paths is None:
|
|
||||||
return None
|
|
||||||
return map(cast_path, paths)
|
|
||||||
|
|
||||||
def is_package(self):
|
def is_package(self):
|
||||||
return self.py__path__() is not None
|
return self.py__path__() is not None
|
||||||
@@ -310,7 +306,7 @@ class CompiledModule(CompiledValue):
|
|||||||
return tuple(name.split('.'))
|
return tuple(name.split('.'))
|
||||||
|
|
||||||
def py__file__(self):
|
def py__file__(self):
|
||||||
path = cast_path(self.access_handle.py__file__())
|
path = self.access_handle.py__file__()
|
||||||
if path is None:
|
if path is None:
|
||||||
return None
|
return None
|
||||||
return Path(path)
|
return Path(path)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from pathlib import Path
|
|||||||
|
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.file_io import FileIO
|
from jedi.file_io import FileIO
|
||||||
from jedi._compatibility import cast_path
|
|
||||||
from jedi.parser_utils import get_cached_code_lines
|
from jedi.parser_utils import get_cached_code_lines
|
||||||
from jedi.inference.base_value import ValueSet, NO_VALUES
|
from jedi.inference.base_value import ValueSet, NO_VALUES
|
||||||
from jedi.inference.gradual.stub_value import TypingModuleWrapper, StubModuleValue
|
from jedi.inference.gradual.stub_value import TypingModuleWrapper, StubModuleValue
|
||||||
@@ -44,7 +43,6 @@ def _create_stub_map(directory_path_info):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for entry in listed:
|
for entry in listed:
|
||||||
entry = cast_path(entry)
|
|
||||||
path = os.path.join(directory_path_info.path, entry)
|
path = os.path.join(directory_path_info.path, entry)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
init = os.path.join(path, '__init__.pyi')
|
init = os.path.join(path, '__init__.pyi')
|
||||||
@@ -169,7 +167,6 @@ def _try_to_load_stub(inference_state, import_names, python_value_set,
|
|||||||
if len(import_names) == 1:
|
if len(import_names) == 1:
|
||||||
# foo-stubs
|
# foo-stubs
|
||||||
for p in sys_path:
|
for p in sys_path:
|
||||||
p = cast_path(p)
|
|
||||||
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
||||||
m = _try_to_load_stub_from_file(
|
m = _try_to_load_stub_from_file(
|
||||||
inference_state,
|
inference_state,
|
||||||
|
|||||||
Reference in New Issue
Block a user