Skip to content

Upgrade Jedi to latest stable (0.13.1) #3113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/2667.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Jedi to 0.13.1 and parso 0.3.1.
2 changes: 1 addition & 1 deletion pythonFiles/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class JediCompletion(object):

def __init__(self):
self.default_sys_path = sys.path
self.environment = jedi.api.environment.Environment(sys.prefix, sys.executable)
self.environment = jedi.api.environment.create_environment(sys.executable)
self._input = io.open(sys.stdin.fileno(), encoding='utf-8')
if (os.path.sep == '/') and (platform.uname()[2].find('Microsoft') > -1):
# WSL; does not support UNC paths
Expand Down
4 changes: 2 additions & 2 deletions pythonFiles/jedi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
... datetime.da'''
>>> script = jedi.Script(source, 3, len('datetime.da'), 'example.py')
>>> script
<Script: 'example.py'>
<Script: 'example.py' ...>
>>> completions = script.completions()
>>> completions #doctest: +ELLIPSIS
[<Completion: date>, <Completion: datetime>, ...]
Expand All @@ -36,7 +36,7 @@
good text editor, while still having very good IDE features for Python.
"""

__version__ = '0.12.0'
__version__ = '0.13.1'

from jedi.api import Script, Interpreter, set_debug_function, \
preload_module, names
Expand Down
202 changes: 138 additions & 64 deletions pythonFiles/jedi/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been
created. Clearly there is huge need to use conforming syntax.
"""
import binascii
import errno
import sys
import os
Expand All @@ -17,8 +16,6 @@
pass

is_py3 = sys.version_info[0] >= 3
is_py33 = is_py3 and sys.version_info[1] >= 3
is_py34 = is_py3 and sys.version_info[1] >= 4
is_py35 = is_py3 and sys.version_info[1] >= 5
py_version = int(str(sys.version_info[0]) + str(sys.version_info[1]))

Expand All @@ -35,24 +32,36 @@ def close(self):
del self.loader


def find_module_py34(string, path=None, full_name=None):
def find_module_py34(string, path=None, full_name=None, is_global_search=True):
spec = None
loader = None

spec = importlib.machinery.PathFinder.find_spec(string, path)
if spec is not None:
# We try to disambiguate implicit namespace pkgs with non implicit namespace pkgs
if not spec.has_location:
full_name = string if not path else full_name
implicit_ns_info = ImplicitNSInfo(full_name, spec.submodule_search_locations._path)
return None, implicit_ns_info, False
for finder in sys.meta_path:
if is_global_search and finder != importlib.machinery.PathFinder:
p = None
else:
p = path
try:
find_spec = finder.find_spec
except AttributeError:
# These are old-school clases that still have a different API, just
# ignore those.
continue

spec = find_spec(string, p)
if spec is not None:
loader = spec.loader
if loader is None and not spec.has_location:
# This is a namespace package.
full_name = string if not path else full_name
implicit_ns_info = ImplicitNSInfo(full_name, spec.submodule_search_locations._path)
return None, implicit_ns_info, False
break

# we have found the tail end of the dotted path
loader = spec.loader
return find_module_py33(string, path, loader)


def find_module_py33(string, path=None, loader=None, full_name=None):
def find_module_py33(string, path=None, loader=None, full_name=None, is_global_search=True):
loader = loader or importlib.machinery.PathFinder.find_module(string, path)

if loader is None and path is None: # Fallback to find builtins
Expand Down Expand Up @@ -105,7 +114,7 @@ def find_module_py33(string, path=None, loader=None, full_name=None):
return module_file, module_path, is_package


def find_module_pre_py33(string, path=None, full_name=None):
def find_module_pre_py34(string, path=None, full_name=None, is_global_search=True):
# This import is here, because in other places it will raise a
# DeprecationWarning.
import imp
Expand Down Expand Up @@ -140,8 +149,7 @@ def find_module_pre_py33(string, path=None, full_name=None):
raise ImportError("No module named {}".format(string))


find_module = find_module_py33 if is_py33 else find_module_pre_py33
find_module = find_module_py34 if is_py34 else find_module
find_module = find_module_py34 if is_py3 else find_module_pre_py34
find_module.__doc__ = """
Provides information about a module.

Expand Down Expand Up @@ -208,6 +216,7 @@ def _iter_modules(paths, prefix=''):
yield importer, prefix + modname, ispkg
# END COPY


iter_modules = _iter_modules if py_version >= 34 else pkgutil.iter_modules


Expand Down Expand Up @@ -253,6 +262,7 @@ def reraise(exception, traceback):

"""


class Python3Method(object):
def __init__(self, func):
self.func = func
Expand Down Expand Up @@ -313,10 +323,10 @@ def force_unicode(obj):
try:
import builtins # module name in python 3
except ImportError:
import __builtin__ as builtins
import __builtin__ as builtins # noqa: F401


import ast
import ast # noqa: F401


def literal_eval(string):
Expand All @@ -326,7 +336,7 @@ def literal_eval(string):
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest # Python 2
from itertools import izip_longest as zip_longest # Python 2 # noqa: F401

try:
FileNotFoundError = FileNotFoundError
Expand Down Expand Up @@ -356,6 +366,7 @@ def print_to_stderr(*args):
eval("print(*args, file=sys.stderr)")
else:
print >> sys.stderr, args
sys.stderr.flush()


def utf8_repr(func):
Expand All @@ -379,10 +390,14 @@ def wrapper(self):
if is_py3:
import queue
else:
import Queue as queue

import Queue as queue # noqa: F401

import pickle
try:
# Attempt to load the C implementation of pickle on Python 2 as it is way
# faster.
import cPickle as pickle
except ImportError:
import pickle
if sys.version_info[:2] == (3, 3):
"""
Monkeypatch the unpickler in Python 3.3. This is needed, because the
Expand Down Expand Up @@ -443,53 +458,45 @@ def loads(s, fix_imports=True, encoding="ASCII", errors="strict"):
pickle.loads = loads


_PICKLE_PROTOCOL = 2
is_windows = sys.platform == 'win32'

# The Windows shell on Python 2 consumes all control characters (below 32) and expand on
# all Python versions \n to \r\n.
# pickle starting from protocol version 1 uses binary data, which could not be escaped by
# any normal unicode encoder. Therefore, the only bytes encoder which doesn't produce
# control characters is binascii.hexlify.


def pickle_load(file):
if is_windows:
try:
data = file.readline()
data = binascii.unhexlify(data.strip())
if is_py3:
return pickle.loads(data, encoding='bytes')
else:
return pickle.loads(data)
# Python on Windows don't throw EOF errors for pipes. So reraise them with
# the correct type, which is cought upwards.
except OSError:
raise EOFError()
else:
try:
if is_py3:
return pickle.load(file, encoding='bytes')
else:
return pickle.load(file)
return pickle.load(file)
# Python on Windows don't throw EOF errors for pipes. So reraise them with
# the correct type, which is caught upwards.
except OSError:
if sys.platform == 'win32':
raise EOFError()
raise


def pickle_dump(data, file):
if is_windows:
try:
data = pickle.dumps(data, protocol=_PICKLE_PROTOCOL)
data = binascii.hexlify(data)
file.write(data)
file.write(b'\n')
# On Python 3.3 flush throws sometimes an error even if the two file writes
# should done it already before. This could be also computer / speed depending.
file.flush()
# Python on Windows don't throw EPIPE errors for pipes. So reraise them with
# the correct type and error number.
except OSError:
raise IOError(errno.EPIPE, "Broken pipe")
else:
pickle.dump(data, file, protocol=_PICKLE_PROTOCOL)
def pickle_dump(data, file, protocol):
try:
pickle.dump(data, file, protocol)
# On Python 3.3 flush throws sometimes an error even though the writing
# operation should be completed.
file.flush()
# Python on Windows don't throw EPIPE errors for pipes. So reraise them with
# the correct type and error number.
except OSError:
if sys.platform == 'win32':
raise IOError(errno.EPIPE, "Broken pipe")
raise


# Determine the highest protocol version compatible for a given list of Python
# versions.
def highest_pickle_protocol(python_versions):
protocol = 4
for version in python_versions:
if version[0] == 2:
# The minimum protocol version for the versions of Python that we
# support (2.7 and 3.3+) is 2.
return 2
if version[1] < 4:
protocol = 3
return protocol


try:
Expand All @@ -512,4 +519,71 @@ def __init__(self, *args, **kwargs):
except AttributeError:
CREATE_NO_WINDOW = 0x08000000
kwargs['creationflags'] = CREATE_NO_WINDOW
# The child process doesn't need file descriptors except 0, 1, 2.
# This is unix only.
kwargs['close_fds'] = 'posix' in sys.builtin_module_names
super(GeneralizedPopen, self).__init__(*args, **kwargs)


# shutil.which is not available on Python 2.7.
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.

`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.

"""
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))

# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None

if path is None:
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = path.split(os.pathsep)

if sys.platform == "win32":
# The current directory takes precedence on Windows.
if os.curdir not in path:
path.insert(0, os.curdir)

# PATHEXT is necessary to check on Windows.
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# others.
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]

seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if normdir not in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None
Loading