forked from VimPlug/jedi
Remove unicode usages
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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 <environments>`
|
||||
@@ -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 "
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user