diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 13c1975c..79962eff 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -26,27 +26,6 @@ is_py35 = is_py3 and sys.version_info[1] >= 5 py_version = int(str(sys.version_info[0]) + str(sys.version_info[1])) -if sys.version_info[:2] < (3, 5): - """ - A super-minimal shim around listdir that behave like - scandir for the information we need. - """ - class _DirEntry: - - def __init__(self, name, basepath): - self.name = name - self.basepath = basepath - - def is_dir(self): - path_for_name = os.path.join(self.basepath, self.name) - return os.path.isdir(path_for_name) - - def scandir(dir): - return [_DirEntry(name, dir) for name in os.listdir(dir)] -else: - from os import scandir - - class DummyFile(object): def __init__(self, loader, string): self.loader = loader diff --git a/jedi/api/file_name.py b/jedi/api/file_name.py index 4d472453..addf4bb6 100644 --- a/jedi/api/file_name.py +++ b/jedi/api/file_name.py @@ -1,6 +1,6 @@ import os -from jedi._compatibility import FileNotFoundError, force_unicode, scandir +from jedi._compatibility import FileNotFoundError, force_unicode from jedi.api import classes from jedi.api.strings import StringName, get_quote_ending from jedi.api.helpers import match @@ -38,7 +38,7 @@ def complete_file_name(inference_state, module_context, start_leaf, quote, strin string = to_be_added + string base_path = os.path.join(inference_state.project.path, string) try: - listed = sorted(scandir(base_path), key=lambda e: e.name) + listed = sorted(os.scandir(base_path), key=lambda e: e.name) # OSError: [Errno 36] File name too long: '...' except (FileNotFoundError, OSError): return diff --git a/jedi/inference/compiled/subprocess/functions.py b/jedi/inference/compiled/subprocess/functions.py index 86b5287b..740b3cdd 100644 --- a/jedi/inference/compiled/subprocess/functions.py +++ b/jedi/inference/compiled/subprocess/functions.py @@ -5,7 +5,7 @@ import re import inspect from jedi._compatibility import find_module, cast_path, force_unicode, \ - all_suffixes, scandir + all_suffixes from jedi.inference.compiled import access from jedi import debug from jedi import parser_utils @@ -90,7 +90,7 @@ def _iter_module_names(inference_state, paths): # Python modules/packages for path in paths: try: - dirs = scandir(path) + dirs = os.scandir(path) except OSError: # The file might not exist or reading it might lead to an error. debug.warning("Not possible to list directory: %s", path) diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 354bd43b..a0d23ef3 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -7,7 +7,6 @@ import pytest from ..helpers import root_dir from jedi.api.helpers import _start_match, _fuzzy_match -from jedi._compatibility import scandir def test_in_whitespace(Script): @@ -88,7 +87,7 @@ def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpd def test_complete_expanduser(Script): - possibilities = scandir(expanduser('~')) + possibilities = os.scandir(expanduser('~')) non_dots = [p for p in possibilities if not p.name.startswith('.') and len(p.name) > 1] item = non_dots[0] line = "'~%s%s'" % (os.sep, item.name)