diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 6bccd3a1..68e8243e 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -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. """ from __future__ import print_function -import atexit import errno -import functools import sys import os import re import pkgutil import warnings import subprocess -import weakref +import pickle + try: import importlib except ImportError: @@ -361,18 +360,9 @@ if is_py3: else: 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): try: - if is_py3: - return pickle.load(file, encoding='bytes') 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. @@ -382,24 +372,8 @@ def pickle_load(file): 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): try: - if not is_py3: - data = _python2_dct_keys_to_unicode(data) pickle.dump(data, file, protocol) # On Python 3.3 flush throws sometimes an error even though the writing # operation should be completed. diff --git a/jedi/inference/compiled/subprocess/__init__.py b/jedi/inference/compiled/subprocess/__init__.py index 56c03df9..97410941 100644 --- a/jedi/inference/compiled/subprocess/__init__.py +++ b/jedi/inference/compiled/subprocess/__init__.py @@ -13,6 +13,7 @@ import subprocess import socket import errno import traceback +import weakref from functools import partial from threading import Thread try: @@ -21,7 +22,7 @@ except ImportError: from Queue import Queue, Empty # python 2.7 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.cache import memoize_method from jedi.inference.compiled.subprocess import functions diff --git a/jedi/inference/gradual/annotation.py b/jedi/inference/gradual/annotation.py index 77a8abc5..1404ecfb 100644 --- a/jedi/inference/gradual/annotation.py +++ b/jedi/inference/gradual/annotation.py @@ -10,6 +10,7 @@ from inspect import Parameter from parso import ParserSyntaxError, parse +from jedi._compatibility import force_unicode from jedi.inference.cache import inference_state_method_cache from jedi.inference.base_value import ValueSet, NO_VALUES from jedi.inference.gradual.base import DefineGenericBaseClass, GenericClass