mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Remove the pickle compatibility stuff
This commit is contained in:
@@ -241,20 +241,6 @@ def pickle_dump(data, file, protocol):
|
||||
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
|
||||
|
||||
|
||||
class GeneralizedPopen(subprocess.Popen):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if os.name == 'nt':
|
||||
|
||||
@@ -9,7 +9,6 @@ import filecmp
|
||||
from collections import namedtuple
|
||||
from shutil import which
|
||||
|
||||
from jedi._compatibility import highest_pickle_protocol
|
||||
from jedi.cache import memoize_method, time_cache
|
||||
from jedi.inference.compiled.subprocess import CompiledSubprocess, \
|
||||
InferenceStateSameProcess, InferenceStateSubprocess
|
||||
@@ -97,16 +96,6 @@ class Environment(_BaseEnvironment):
|
||||
Like :data:`sys.version_info`: a tuple to show the current
|
||||
Environment's Python version.
|
||||
"""
|
||||
|
||||
# py2 sends bytes via pickle apparently?!
|
||||
if self.version_info.major == 2:
|
||||
self.executable = self.executable.decode()
|
||||
self.path = self.path.decode()
|
||||
|
||||
# Adjust pickle protocol according to host and client version.
|
||||
self._subprocess._pickle_protocol = highest_pickle_protocol([
|
||||
sys.version_info, self.version_info])
|
||||
|
||||
return self._subprocess
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -29,6 +29,7 @@ from jedi.api.exceptions import InternalError
|
||||
|
||||
|
||||
_MAIN_PATH = os.path.join(os.path.dirname(__file__), '__main__.py')
|
||||
PICKLE_PROTOCOL = 4
|
||||
|
||||
|
||||
def _enqueue_output(out, queue_):
|
||||
@@ -151,8 +152,6 @@ class InferenceStateSubprocess(_InferenceStateProcess):
|
||||
|
||||
class CompiledSubprocess(object):
|
||||
is_crashed = False
|
||||
# Start with 2, gets set after _get_info.
|
||||
_pickle_protocol = 2
|
||||
|
||||
def __init__(self, executable, env_vars={}):
|
||||
self._executable = executable
|
||||
@@ -171,10 +170,9 @@ class CompiledSubprocess(object):
|
||||
|
||||
def __repr__(self):
|
||||
pid = os.getpid()
|
||||
return '<%s _executable=%r, _pickle_protocol=%r, is_crashed=%r, pid=%r>' % (
|
||||
return '<%s _executable=%r, is_crashed=%r, pid=%r>' % (
|
||||
self.__class__.__name__,
|
||||
self._executable,
|
||||
self._pickle_protocol,
|
||||
self.is_crashed,
|
||||
pid,
|
||||
)
|
||||
@@ -244,7 +242,7 @@ class CompiledSubprocess(object):
|
||||
|
||||
data = inference_state_id, function, args, kwargs
|
||||
try:
|
||||
pickle_dump(data, self._get_process().stdin, self._pickle_protocol)
|
||||
pickle_dump(data, self._get_process().stdin, PICKLE_PROTOCOL)
|
||||
except (socket.error, IOError) as e:
|
||||
# Once Python2 will be removed we can just use `BrokenPipeError`.
|
||||
# Also, somehow in windows it returns EINVAL instead of EPIPE if
|
||||
@@ -293,12 +291,11 @@ class CompiledSubprocess(object):
|
||||
|
||||
|
||||
class Listener(object):
|
||||
def __init__(self, pickle_protocol):
|
||||
def __init__(self):
|
||||
self._inference_states = {}
|
||||
# TODO refactor so we don't need to process anymore just handle
|
||||
# controlling.
|
||||
self._process = _InferenceStateProcess(Listener)
|
||||
self._pickle_protocol = pickle_protocol
|
||||
|
||||
def _get_inference_state(self, function, inference_state_id):
|
||||
from jedi.inference import InferenceState
|
||||
@@ -363,7 +360,7 @@ class Listener(object):
|
||||
except Exception as e:
|
||||
result = True, traceback.format_exc(), e
|
||||
|
||||
pickle_dump(result, stdout, self._pickle_protocol)
|
||||
pickle_dump(result, stdout, PICKLE_PROTOCOL)
|
||||
|
||||
|
||||
class AccessHandle(object):
|
||||
|
||||
@@ -30,14 +30,10 @@ class _ExactImporter(object):
|
||||
|
||||
# Try to import jedi/parso.
|
||||
sys.meta_path.insert(0, _ExactImporter(_get_paths()))
|
||||
from jedi.inference.compiled import subprocess # NOQA
|
||||
from jedi.inference.compiled import subprocess # noqa: E402
|
||||
sys.meta_path.pop(0)
|
||||
|
||||
from jedi._compatibility import highest_pickle_protocol # noqa: E402
|
||||
|
||||
|
||||
# Retrieve the pickle protocol.
|
||||
host_sys_version = [int(x) for x in sys.argv[2].split('.')]
|
||||
pickle_protocol = highest_pickle_protocol([sys.version_info, host_sys_version])
|
||||
# And finally start the client.
|
||||
subprocess.Listener(pickle_protocol=pickle_protocol).listen()
|
||||
subprocess.Listener().listen()
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
from collections import namedtuple
|
||||
from jedi._compatibility import highest_pickle_protocol
|
||||
|
||||
|
||||
def test_highest_pickle_protocol():
|
||||
v = namedtuple('version', 'major, minor')
|
||||
assert highest_pickle_protocol([v(2, 7), v(2, 7)]) == 2
|
||||
assert highest_pickle_protocol([v(2, 7), v(3, 8)]) == 2
|
||||
assert highest_pickle_protocol([v(2, 7), v(3, 5)]) == 2
|
||||
assert highest_pickle_protocol([v(2, 7), v(3, 6)]) == 2
|
||||
assert highest_pickle_protocol([v(3, 8), v(2, 7)]) == 2
|
||||
assert highest_pickle_protocol([v(3, 8), v(3, 8)]) == 4
|
||||
assert highest_pickle_protocol([v(3, 8), v(3, 5)]) == 4
|
||||
assert highest_pickle_protocol([v(3, 8), v(3, 6)]) == 4
|
||||
assert highest_pickle_protocol([v(3, 6), v(2, 7)]) == 2
|
||||
assert highest_pickle_protocol([v(3, 6), v(3, 8)]) == 4
|
||||
assert highest_pickle_protocol([v(3, 6), v(3, 5)]) == 4
|
||||
assert highest_pickle_protocol([v(3, 6), v(3, 6)]) == 4
|
||||
Reference in New Issue
Block a user