1
0
forked from VimPlug/jedi

Remove unicode usages

This commit is contained in:
Dave Halter
2020-07-02 03:26:22 +02:00
parent 5a912de937
commit 8ee0c8593e
15 changed files with 13 additions and 56 deletions

View File

@@ -134,13 +134,6 @@ class ImplicitNSInfo(object):
self.paths = paths self.paths = paths
# unicode function
try:
unicode = unicode
except NameError:
unicode = str
try: try:
encoding = sys.stdout.encoding encoding = sys.stdout.encoding
if encoding is None: if encoding is None:
@@ -156,7 +149,7 @@ def u(string, errors='strict'):
unicode, because we check that in the beginning). unicode, because we check that in the beginning).
""" """
if isinstance(string, bytes): if isinstance(string, bytes):
return unicode(string, encoding='UTF-8', errors=errors) return str(string, encoding='UTF-8', errors=errors)
return string return string

View File

@@ -97,9 +97,6 @@ class Script(object):
:param path: The path of the file in the file system, or ``''`` if :param path: The path of the file in the file system, or ``''`` if
it hasn't been saved yet. it hasn't been saved yet.
:type path: str or None :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. :param sys_path: Deprecated, use the project parameter.
:type sys_path: typing.List[str] :type sys_path: typing.List[str]
:param Environment environment: Provide a predefined :ref:`Environment <environments>` :param Environment environment: Provide a predefined :ref:`Environment <environments>`
@@ -115,15 +112,6 @@ class Script(object):
# An empty path (also empty string) should always result in no path. # An empty path (also empty string) should always result in no path.
self.path = os.path.abspath(path) if path else None 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: if line is not None:
warnings.warn( warnings.warn(
"Providing the line is now done in the functions themselves " "Providing the line is now done in the functions themselves "

View File

@@ -160,7 +160,7 @@ class BaseName(object):
Finally, here is what you can get from :attr:`type`: 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] >>> defs[0]
'module' 'module'
>>> defs[1] >>> defs[1]

View File

@@ -21,9 +21,6 @@ def imitate_pydoc(string):
if pydoc_topics is None: if pydoc_topics is None:
return '' return ''
# str needed because of possible unicode stuff in py2k (pydoc doesn't work
# with unicode strings)
string = str(string)
h = pydoc.help h = pydoc.help
with suppress(KeyError): with suppress(KeyError):
# try to access symbols # try to access symbols

View File

@@ -9,7 +9,6 @@ names in a module, but pretty much an arbitrary string.
""" """
import re import re
from jedi._compatibility import unicode
from jedi.inference.names import AbstractArbitraryName from jedi.inference.names import AbstractArbitraryName
from jedi.inference.helpers import infer_call_of_leaf from jedi.inference.helpers import infer_call_of_leaf
from jedi.api.classes import Completion 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): 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) return repr(dict_key)
r = repr(dict_key) r = repr(dict_key)

View File

@@ -49,13 +49,10 @@ class Error(object):
first = self.__class__.__name__[0] first = self.__class__.__name__[0]
return first + str(CODES[self.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, return '%s:%s:%s: %s %s' % (self.path, self.line, self.column,
self.code, self.message) self.code, self.message)
def __str__(self):
return self.__unicode__()
def __eq__(self, other): def __eq__(self, other):
return (self.path == other.path and self.name == other.name return (self.path == other.path and self.name == other.name
and self._start_pos == other._start_pos) and self._start_pos == other._start_pos)

View File

@@ -13,7 +13,6 @@ from itertools import zip_longest
from parso.python.tree import Name from parso.python.tree import Name
from jedi import debug from jedi import debug
from jedi._compatibility import unicode
from jedi.parser_utils import clean_scope_docstring from jedi.parser_utils import clean_scope_docstring
from jedi.inference.helpers import SimpleGetItemNotFound from jedi.inference.helpers import SimpleGetItemNotFound
from jedi.inference.utils import safe_property from jedi.inference.utils import safe_property
@@ -384,7 +383,7 @@ def _getitem(value, index_values, contextualized_node):
unused_values = set() unused_values = set()
for index_value in index_values: for index_value in index_values:
index = index_value.get_safe_value(default=None) 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: try:
result |= value.py__simple_getitem__(index) result |= value.py__simple_getitem__(index)
continue continue

View File

@@ -1,4 +1,3 @@
from jedi._compatibility import unicode
from jedi.inference.compiled.value import CompiledValue, CompiledName, \ from jedi.inference.compiled.value import CompiledValue, CompiledName, \
CompiledValueFilter, CompiledValueName, create_from_access_path CompiledValueFilter, CompiledValueName, create_from_access_path
from jedi.inference.base_value import LazyValueWrapper 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 Only allows creations of objects that are easily picklable across Python
versions. 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( compiled_value = create_from_access_path(
inference_state, inference_state,
inference_state.compiled_subprocess.create_simple_object(obj) inference_state.compiled_subprocess.create_simple_object(obj)

View File

@@ -7,10 +7,9 @@ import warnings
import re import re
import builtins import builtins
from jedi._compatibility import unicode
from jedi.inference.compiled.getattr_static import getattr_static 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) MethodDescriptorType = type(str.replace)
# These are not considered classes and access is granted even though they have # 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 # Avoid some weird hacks that would just fail, because they cannot be
# used by pickle. # used by pickle.
if not isinstance(paths, list) \ 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 None
return paths return paths
@@ -383,7 +382,7 @@ class DirectObjectAccess(object):
return [self._create_access(module), access] return [self._create_access(module), access]
def get_safe_value(self): 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 return self._obj
raise ValueError("Object is type %s and not simple" % type(self._obj)) raise ValueError("Object is type %s and not simple" % type(self._obj))

View File

@@ -1,4 +1,3 @@
from jedi._compatibility import unicode
from jedi import debug from jedi import debug
from jedi.inference.base_value import ValueSet, NO_VALUES, ValueWrapper from jedi.inference.base_value import ValueSet, NO_VALUES, ValueWrapper
from jedi.inference.gradual.base import BaseTypingValue from jedi.inference.gradual.base import BaseTypingValue
@@ -40,7 +39,7 @@ class TypeVarClass(BaseTypingValue):
return None return None
else: else:
safe_value = method(default=None) safe_value = method(default=None)
if isinstance(safe_value, (str, unicode)): if isinstance(safe_value, str):
return safe_value return safe_value
return None return None

View File

@@ -7,7 +7,6 @@ This file deals with all the typing.py cases.
""" """
import itertools import itertools
from jedi._compatibility import unicode
from jedi import debug from jedi import debug
from jedi.inference.compiled import builtin_from_name, create_simple_object from jedi.inference.compiled import builtin_from_name, create_simple_object
from jedi.inference.base_value import ValueSet, NO_VALUES, Value, \ from jedi.inference.base_value import ValueSet, NO_VALUES, Value, \
@@ -459,7 +458,7 @@ class TypedDict(LazyValueWrapper):
return ValueName(self, self.tree_node.name) return ValueName(self, self.tree_node.name)
def py__simple_getitem__(self, index): def py__simple_getitem__(self, index):
if isinstance(index, unicode): if isinstance(index, str):
return ValueSet.from_sets( return ValueSet.from_sets(
name.infer() name.infer()
for filter in self._definition_class.get_filters(is_instance=True) for filter in self._definition_class.get_filters(is_instance=True)

View File

@@ -7,8 +7,6 @@ from contextlib import contextmanager
from parso.python import tree from parso.python import tree
from jedi._compatibility import unicode
def is_stdlib_path(path): def is_stdlib_path(path):
# Python standard library paths look like this: # Python standard library paths look like this:

View File

@@ -5,7 +5,6 @@ import copy
from parso.python import tree from parso.python import tree
from jedi._compatibility import unicode
from jedi import debug from jedi import debug
from jedi import parser_utils from jedi import parser_utils
from jedi.inference.base_value import ValueSet, NO_VALUES, ContextualizedNode, \ 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): def _infer_comparison_part(inference_state, context, left, operator, right):
l_is_num = is_number(left) l_is_num = is_number(left)
r_is_num = is_number(right) r_is_num = is_number(right)
if isinstance(operator, unicode): if isinstance(operator, str):
str_operator = operator str_operator = operator
else: else:
str_operator = str(operator.value) str_operator = str(operator.value)

View File

@@ -2,7 +2,6 @@ import os
import re import re
from importlib.machinery import all_suffixes from importlib.machinery import all_suffixes
from jedi._compatibility import 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 ContextualizedNode from jedi.inference.base_value import ContextualizedNode
from jedi.inference.helpers import is_string, get_str_or_none 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: except (UnicodeDecodeError, IOError) as e:
# Probably a binary file; permission error or race cond. because # Probably a binary file; permission error or race cond. because
# file got deleted. Ignore it. # file got deleted. Ignore it.
debug.warning(unicode(e)) debug.warning(e)
continue continue

View File

@@ -3,8 +3,6 @@ import warnings
import pytest import pytest
from jedi._compatibility import u
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def check_for_warning(recwarn): def check_for_warning(recwarn):
@@ -40,9 +38,3 @@ def test_usages(Script):
def test_call_signatures(Script): def test_call_signatures(Script):
d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures() d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures()
assert d1.name == 'abs' assert d1.name == 'abs'
def test_encoding_parameter(Script):
name = u('')
s = Script(name.encode('latin-1'), encoding='latin-1')
assert s._module_node.get_code() == name