Remove the scandir compatibility

This commit is contained in:
Dave Halter
2020-07-02 00:38:44 +02:00
parent fb34df3987
commit 3262ad4350
4 changed files with 5 additions and 27 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)