diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index f06327be..3b3e24fb 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -134,13 +134,6 @@ class ImplicitNSInfo(object): self.paths = paths -# unicode function -try: - unicode = unicode -except NameError: - unicode = str - - try: encoding = sys.stdout.encoding if encoding is None: @@ -156,7 +149,7 @@ def u(string, errors='strict'): unicode, because we check that in the beginning). """ if isinstance(string, bytes): - return unicode(string, encoding='UTF-8', errors=errors) + return str(string, encoding='UTF-8', errors=errors) return string diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 1bf4e756..2c9b3ef6 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -97,9 +97,6 @@ class Script(object): :param path: The path of the file in the file system, or ``''`` if it hasn't been saved yet. :type path: str or None - :param encoding: Deprecated, cast to unicode yourself. The encoding of - ``code``, if it is not a ``unicode`` object (default ``'utf-8'``). - :type encoding: str :param sys_path: Deprecated, use the project parameter. :type sys_path: typing.List[str] :param Environment environment: Provide a predefined :ref:`Environment ` @@ -115,15 +112,6 @@ class Script(object): # An empty path (also empty string) should always result in no path. self.path = os.path.abspath(path) if path else None - if encoding is None: - encoding = 'utf-8' - else: - warnings.warn( - "Deprecated since version 0.17.0. You should cast to valid " - "unicode yourself, especially if you are not using utf-8.", - DeprecationWarning, - stacklevel=2 - ) if line is not None: warnings.warn( "Providing the line is now done in the functions themselves " diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 0ba7c3b7..622ec460 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -160,7 +160,7 @@ class BaseName(object): Finally, here is what you can get from :attr:`type`: - >>> defs = [str(d.type) for d in defs] # It's unicode and in Py2 has u before it. + >>> defs = [d.type for d in defs] >>> defs[0] 'module' >>> defs[1] diff --git a/jedi/api/keywords.py b/jedi/api/keywords.py index 999e5dc2..df216f98 100644 --- a/jedi/api/keywords.py +++ b/jedi/api/keywords.py @@ -21,9 +21,6 @@ def imitate_pydoc(string): if pydoc_topics is None: return '' - # str needed because of possible unicode stuff in py2k (pydoc doesn't work - # with unicode strings) - string = str(string) h = pydoc.help with suppress(KeyError): # try to access symbols diff --git a/jedi/api/strings.py b/jedi/api/strings.py index 6653671e..075f10cc 100644 --- a/jedi/api/strings.py +++ b/jedi/api/strings.py @@ -9,7 +9,6 @@ names in a module, but pretty much an arbitrary string. """ import re -from jedi._compatibility import unicode from jedi.inference.names import AbstractArbitraryName from jedi.inference.helpers import infer_call_of_leaf from jedi.api.classes import Completion @@ -65,7 +64,7 @@ def _completions_for_dicts(inference_state, dicts, literal_string, cut_end_quote def _create_repr_string(literal_string, dict_key): - if not isinstance(dict_key, (unicode, bytes)) or not literal_string: + if not isinstance(dict_key, (str, bytes)) or not literal_string: return repr(dict_key) r = repr(dict_key) diff --git a/jedi/inference/analysis.py b/jedi/inference/analysis.py index df76bf82..1e51db55 100644 --- a/jedi/inference/analysis.py +++ b/jedi/inference/analysis.py @@ -49,13 +49,10 @@ class Error(object): first = self.__class__.__name__[0] return first + str(CODES[self.name][0]) - def __unicode__(self): + def __str__(self): return '%s:%s:%s: %s %s' % (self.path, self.line, self.column, self.code, self.message) - def __str__(self): - return self.__unicode__() - def __eq__(self, other): return (self.path == other.path and self.name == other.name and self._start_pos == other._start_pos) diff --git a/jedi/inference/base_value.py b/jedi/inference/base_value.py index e51f3e66..01c4e7d1 100644 --- a/jedi/inference/base_value.py +++ b/jedi/inference/base_value.py @@ -13,7 +13,6 @@ from itertools import zip_longest from parso.python.tree import Name from jedi import debug -from jedi._compatibility import unicode from jedi.parser_utils import clean_scope_docstring from jedi.inference.helpers import SimpleGetItemNotFound from jedi.inference.utils import safe_property @@ -384,7 +383,7 @@ def _getitem(value, index_values, contextualized_node): unused_values = set() for index_value in index_values: index = index_value.get_safe_value(default=None) - if type(index) in (float, int, str, unicode, slice, bytes): + if type(index) in (float, int, str, slice, bytes): try: result |= value.py__simple_getitem__(index) continue diff --git a/jedi/inference/compiled/__init__.py b/jedi/inference/compiled/__init__.py index b5d435fc..ecb03372 100644 --- a/jedi/inference/compiled/__init__.py +++ b/jedi/inference/compiled/__init__.py @@ -1,4 +1,3 @@ -from jedi._compatibility import unicode from jedi.inference.compiled.value import CompiledValue, CompiledName, \ CompiledValueFilter, CompiledValueName, create_from_access_path from jedi.inference.base_value import LazyValueWrapper @@ -45,7 +44,7 @@ def create_simple_object(inference_state, obj): Only allows creations of objects that are easily picklable across Python versions. """ - assert type(obj) in (int, float, str, bytes, unicode, slice, complex, bool), obj + assert type(obj) in (int, float, str, bytes, slice, complex, bool), obj compiled_value = create_from_access_path( inference_state, inference_state.compiled_subprocess.create_simple_object(obj) diff --git a/jedi/inference/compiled/access.py b/jedi/inference/compiled/access.py index ce524ff1..1482cabb 100644 --- a/jedi/inference/compiled/access.py +++ b/jedi/inference/compiled/access.py @@ -7,10 +7,9 @@ import warnings import re import builtins -from jedi._compatibility import unicode from jedi.inference.compiled.getattr_static import getattr_static -ALLOWED_GETITEM_TYPES = (str, list, tuple, unicode, bytes, bytearray, dict) +ALLOWED_GETITEM_TYPES = (str, list, tuple, bytes, bytearray, dict) MethodDescriptorType = type(str.replace) # These are not considered classes and access is granted even though they have @@ -250,7 +249,7 @@ class DirectObjectAccess(object): # Avoid some weird hacks that would just fail, because they cannot be # used by pickle. if not isinstance(paths, list) \ - or not all(isinstance(p, (bytes, unicode)) for p in paths): + or not all(isinstance(p, str) for p in paths): return None return paths @@ -383,7 +382,7 @@ class DirectObjectAccess(object): return [self._create_access(module), access] def get_safe_value(self): - if type(self._obj) in (bool, bytes, float, int, str, unicode, slice) or self._obj is None: + if type(self._obj) in (bool, bytes, float, int, str, slice) or self._obj is None: return self._obj raise ValueError("Object is type %s and not simple" % type(self._obj)) diff --git a/jedi/inference/gradual/type_var.py b/jedi/inference/gradual/type_var.py index 2d508ed8..445fb2ad 100644 --- a/jedi/inference/gradual/type_var.py +++ b/jedi/inference/gradual/type_var.py @@ -1,4 +1,3 @@ -from jedi._compatibility import unicode from jedi import debug from jedi.inference.base_value import ValueSet, NO_VALUES, ValueWrapper from jedi.inference.gradual.base import BaseTypingValue @@ -40,7 +39,7 @@ class TypeVarClass(BaseTypingValue): return None else: safe_value = method(default=None) - if isinstance(safe_value, (str, unicode)): + if isinstance(safe_value, str): return safe_value return None diff --git a/jedi/inference/gradual/typing.py b/jedi/inference/gradual/typing.py index 94f87ede..2d8a0cb0 100644 --- a/jedi/inference/gradual/typing.py +++ b/jedi/inference/gradual/typing.py @@ -7,7 +7,6 @@ This file deals with all the typing.py cases. """ import itertools -from jedi._compatibility import unicode from jedi import debug from jedi.inference.compiled import builtin_from_name, create_simple_object from jedi.inference.base_value import ValueSet, NO_VALUES, Value, \ @@ -459,7 +458,7 @@ class TypedDict(LazyValueWrapper): return ValueName(self, self.tree_node.name) def py__simple_getitem__(self, index): - if isinstance(index, unicode): + if isinstance(index, str): return ValueSet.from_sets( name.infer() for filter in self._definition_class.get_filters(is_instance=True) diff --git a/jedi/inference/helpers.py b/jedi/inference/helpers.py index 8f9fa7c8..32650ba8 100644 --- a/jedi/inference/helpers.py +++ b/jedi/inference/helpers.py @@ -7,8 +7,6 @@ from contextlib import contextmanager from parso.python import tree -from jedi._compatibility import unicode - def is_stdlib_path(path): # Python standard library paths look like this: diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index af08a940..a7565e41 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -5,7 +5,6 @@ import copy from parso.python import tree -from jedi._compatibility import unicode from jedi import debug from jedi import parser_utils from jedi.inference.base_value import ValueSet, NO_VALUES, ContextualizedNode, \ @@ -587,7 +586,7 @@ def _get_tuple_ints(value): def _infer_comparison_part(inference_state, context, left, operator, right): l_is_num = is_number(left) r_is_num = is_number(right) - if isinstance(operator, unicode): + if isinstance(operator, str): str_operator = operator else: str_operator = str(operator.value) diff --git a/jedi/inference/sys_path.py b/jedi/inference/sys_path.py index d16529c2..fd27bff0 100644 --- a/jedi/inference/sys_path.py +++ b/jedi/inference/sys_path.py @@ -2,7 +2,6 @@ import os import re from importlib.machinery import all_suffixes -from jedi._compatibility import unicode from jedi.inference.cache import inference_state_method_cache from jedi.inference.base_value import ContextualizedNode from jedi.inference.helpers import is_string, get_str_or_none @@ -203,7 +202,7 @@ def _get_buildout_script_paths(search_path): except (UnicodeDecodeError, IOError) as e: # Probably a binary file; permission error or race cond. because # file got deleted. Ignore it. - debug.warning(unicode(e)) + debug.warning(e) continue diff --git a/test/test_deprecation.py b/test/test_deprecation.py index 5c4425c7..ad698250 100644 --- a/test/test_deprecation.py +++ b/test/test_deprecation.py @@ -3,8 +3,6 @@ import warnings import pytest -from jedi._compatibility import u - @pytest.fixture(autouse=True) def check_for_warning(recwarn): @@ -40,9 +38,3 @@ def test_usages(Script): def test_call_signatures(Script): d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures() assert d1.name == 'abs' - - -def test_encoding_parameter(Script): - name = u('hö') - s = Script(name.encode('latin-1'), encoding='latin-1') - assert s._module_node.get_code() == name