Remove some pickle compatibility

This commit is contained in:
Dave Halter
2020-07-02 00:46:44 +02:00
parent 395f7fc59e
commit 4e2ca9e5fd
3 changed files with 5 additions and 29 deletions

View File

@@ -3,16 +3,15 @@ To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been
created. Clearly there is huge need to use conforming syntax. created. Clearly there is huge need to use conforming syntax.
""" """
from __future__ import print_function from __future__ import print_function
import atexit
import errno import errno
import functools
import sys import sys
import os import os
import re import re
import pkgutil import pkgutil
import warnings import warnings
import subprocess import subprocess
import weakref import pickle
try: try:
import importlib import importlib
except ImportError: except ImportError:
@@ -361,18 +360,9 @@ if is_py3:
else: else:
import Queue as queue # noqa: F401 import Queue as queue # noqa: F401
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
def pickle_load(file): def pickle_load(file):
try: try:
if is_py3:
return pickle.load(file, encoding='bytes')
return pickle.load(file) return pickle.load(file)
# Python on Windows don't throw EOF errors for pipes. So reraise them with # Python on Windows don't throw EOF errors for pipes. So reraise them with
# the correct type, which is caught upwards. # the correct type, which is caught upwards.
@@ -382,24 +372,8 @@ def pickle_load(file):
raise raise
def _python2_dct_keys_to_unicode(data):
"""
Python 2 stores object __dict__ entries as bytes, not unicode, correct it
here. Python 2 can deal with both, Python 3 expects unicode.
"""
if isinstance(data, tuple):
return tuple(_python2_dct_keys_to_unicode(x) for x in data)
elif isinstance(data, list):
return list(_python2_dct_keys_to_unicode(x) for x in data)
elif hasattr(data, '__dict__') and type(data.__dict__) == dict:
data.__dict__ = {unicode(k): v for k, v in data.__dict__.items()}
return data
def pickle_dump(data, file, protocol): def pickle_dump(data, file, protocol):
try: try:
if not is_py3:
data = _python2_dct_keys_to_unicode(data)
pickle.dump(data, file, protocol) pickle.dump(data, file, protocol)
# On Python 3.3 flush throws sometimes an error even though the writing # On Python 3.3 flush throws sometimes an error even though the writing
# operation should be completed. # operation should be completed.

View File

@@ -13,6 +13,7 @@ import subprocess
import socket import socket
import errno import errno
import traceback import traceback
import weakref
from functools import partial from functools import partial
from threading import Thread from threading import Thread
try: try:
@@ -21,7 +22,7 @@ except ImportError:
from Queue import Queue, Empty # python 2.7 from Queue import Queue, Empty # python 2.7
from jedi._compatibility import queue, is_py3, force_unicode, \ from jedi._compatibility import queue, is_py3, force_unicode, \
pickle_dump, pickle_load, GeneralizedPopen, weakref pickle_dump, pickle_load, GeneralizedPopen
from jedi import debug from jedi import debug
from jedi.cache import memoize_method from jedi.cache import memoize_method
from jedi.inference.compiled.subprocess import functions from jedi.inference.compiled.subprocess import functions

View File

@@ -10,6 +10,7 @@ from inspect import Parameter
from parso import ParserSyntaxError, parse from parso import ParserSyntaxError, parse
from jedi._compatibility import force_unicode
from jedi.inference.cache import inference_state_method_cache from jedi.inference.cache import inference_state_method_cache
from jedi.inference.base_value import ValueSet, NO_VALUES from jedi.inference.base_value import ValueSet, NO_VALUES
from jedi.inference.gradual.base import DefineGenericBaseClass, GenericClass from jedi.inference.gradual.base import DefineGenericBaseClass, GenericClass