mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Remove force_unicode
This commit is contained in:
@@ -192,12 +192,6 @@ def cast_path(obj):
|
||||
return u(obj, errors='replace')
|
||||
|
||||
|
||||
def force_unicode(obj):
|
||||
# Intentionally don't mix those two up, because those two code paths might
|
||||
# be different in the future (maybe windows?).
|
||||
return cast_path(obj)
|
||||
|
||||
|
||||
def pickle_load(file):
|
||||
try:
|
||||
return pickle.load(file)
|
||||
|
||||
@@ -15,7 +15,7 @@ from functools import wraps
|
||||
import parso
|
||||
from parso.python import tree
|
||||
|
||||
from jedi._compatibility import force_unicode, cast_path, is_py3
|
||||
from jedi._compatibility import cast_path
|
||||
from jedi.parser_utils import get_executable_nodes
|
||||
from jedi import debug
|
||||
from jedi import settings
|
||||
@@ -163,9 +163,6 @@ class Script(object):
|
||||
with open(path, 'rb') as f:
|
||||
code = f.read()
|
||||
|
||||
if sys_path is not None and not is_py3:
|
||||
sys_path = list(map(force_unicode, sys_path))
|
||||
|
||||
if project is None:
|
||||
# Load the Python grammar of the current interpreter.
|
||||
project = get_default_project(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
|
||||
from jedi._compatibility import force_unicode
|
||||
from jedi.api import classes
|
||||
from jedi.api.strings import StringName, get_quote_ending
|
||||
from jedi.api.helpers import match
|
||||
@@ -94,7 +93,7 @@ def _add_strings(context, nodes, add_slash=False):
|
||||
return None
|
||||
if not first and add_slash:
|
||||
string += os.path.sep
|
||||
string += force_unicode(s)
|
||||
string += s
|
||||
first = False
|
||||
return string
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ from jedi.api.environment import get_cached_default_environment, create_environm
|
||||
from jedi.api.exceptions import WrongVersion
|
||||
from jedi.api.completion import search_in_module
|
||||
from jedi.api.helpers import split_search_string, get_module_names
|
||||
from jedi._compatibility import force_unicode
|
||||
from jedi.inference.imports import load_module_from_path, \
|
||||
load_namespace_from_path, iter_module_names
|
||||
from jedi.inference.sys_path import discover_buildout_paths
|
||||
@@ -59,10 +58,6 @@ def _remove_duplicates_from_path(path):
|
||||
yield p
|
||||
|
||||
|
||||
def _force_unicode_list(lst):
|
||||
return list(map(force_unicode, lst))
|
||||
|
||||
|
||||
class Project(object):
|
||||
"""
|
||||
Projects are a simple way to manage Python folders and define how Jedi does
|
||||
@@ -207,7 +202,7 @@ class Project(object):
|
||||
prefixed.append(self._path)
|
||||
|
||||
path = prefixed + sys_path + suffixed
|
||||
return list(_force_unicode_list(_remove_duplicates_from_path(path)))
|
||||
return list(_remove_duplicates_from_path(path))
|
||||
|
||||
def get_environment(self):
|
||||
if self._environment is None:
|
||||
|
||||
@@ -3,7 +3,6 @@ Module for statical analysis.
|
||||
"""
|
||||
from parso.python import tree
|
||||
|
||||
from jedi._compatibility import force_unicode
|
||||
from jedi import debug
|
||||
from jedi.inference.helpers import is_string
|
||||
|
||||
@@ -193,7 +192,7 @@ def _check_for_exception_catch(node_context, jedi_name, exception, payload=None)
|
||||
key, lazy_value = unpacked_args[1]
|
||||
names = list(lazy_value.infer())
|
||||
assert len(names) == 1 and is_string(names[0])
|
||||
assert force_unicode(names[0].get_safe_value()) == payload[1].value
|
||||
assert names[0].get_safe_value() == payload[1].value
|
||||
|
||||
# Check objects
|
||||
key, lazy_value = unpacked_args[0]
|
||||
|
||||
@@ -8,7 +8,7 @@ import warnings
|
||||
import re
|
||||
import builtins
|
||||
|
||||
from jedi._compatibility import unicode, is_py3, py_version, force_unicode
|
||||
from jedi._compatibility import unicode, is_py3, py_version
|
||||
from jedi.inference.compiled.getattr_static import getattr_static
|
||||
|
||||
ALLOWED_GETITEM_TYPES = (str, list, tuple, unicode, bytes, bytearray, dict)
|
||||
@@ -159,10 +159,6 @@ def create_access_path(inference_state, obj):
|
||||
return AccessPath(access.get_access_path_tuples())
|
||||
|
||||
|
||||
def _force_unicode_decorator(func):
|
||||
return lambda *args, **kwargs: force_unicode(func(*args, **kwargs))
|
||||
|
||||
|
||||
def get_api_type(obj):
|
||||
if inspect.isclass(obj):
|
||||
return u'class'
|
||||
@@ -199,7 +195,7 @@ class DirectObjectAccess(object):
|
||||
return None
|
||||
|
||||
def py__doc__(self):
|
||||
return force_unicode(inspect.getdoc(self._obj)) or u''
|
||||
return inspect.getdoc(self._obj) or ''
|
||||
|
||||
def py__name__(self):
|
||||
if not _is_class_instance(self._obj) or \
|
||||
@@ -214,7 +210,7 @@ class DirectObjectAccess(object):
|
||||
return None
|
||||
|
||||
try:
|
||||
return force_unicode(cls.__name__)
|
||||
return cls.__name__
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
@@ -264,7 +260,6 @@ class DirectObjectAccess(object):
|
||||
return None
|
||||
return paths
|
||||
|
||||
@_force_unicode_decorator
|
||||
@shorten_repr
|
||||
def get_repr(self):
|
||||
if inspect.ismodule(self._obj):
|
||||
@@ -308,10 +303,10 @@ class DirectObjectAccess(object):
|
||||
name = try_to_get_name(type(self._obj))
|
||||
if name is None:
|
||||
return ()
|
||||
return tuple(force_unicode(n) for n in name.split('.'))
|
||||
return tuple(name.split('.'))
|
||||
|
||||
def dir(self):
|
||||
return list(map(force_unicode, dir(self._obj)))
|
||||
return dir(self._obj)
|
||||
|
||||
def has_iter(self):
|
||||
try:
|
||||
@@ -539,7 +534,7 @@ class DirectObjectAccess(object):
|
||||
objects of an objects
|
||||
"""
|
||||
tuples = dict(
|
||||
(force_unicode(name), self.is_allowed_getattr(name))
|
||||
(name, self.is_allowed_getattr(name))
|
||||
for name in self.dir()
|
||||
)
|
||||
return self.needs_type_completions(), tuples
|
||||
|
||||
@@ -18,7 +18,7 @@ import weakref
|
||||
from functools import partial
|
||||
from threading import Thread
|
||||
|
||||
from jedi._compatibility import is_py3, force_unicode, \
|
||||
from jedi._compatibility import is_py3, \
|
||||
pickle_dump, pickle_load, GeneralizedPopen
|
||||
from jedi import debug
|
||||
from jedi.cache import memoize_method
|
||||
@@ -236,10 +236,6 @@ class CompiledSubprocess(object):
|
||||
if self.is_crashed:
|
||||
raise InternalError("The subprocess %s has crashed." % self._executable)
|
||||
|
||||
if not is_py3:
|
||||
# Python 2 compatibility
|
||||
kwargs = {force_unicode(key): value for key, value in kwargs.items()}
|
||||
|
||||
data = inference_state_id, function, args, kwargs
|
||||
try:
|
||||
pickle_dump(data, self._get_process().stdin, PICKLE_PROTOCOL)
|
||||
@@ -389,9 +385,8 @@ class AccessHandle(object):
|
||||
if name in ('id', 'access') or name.startswith('_'):
|
||||
raise AttributeError("Something went wrong with unpickling")
|
||||
|
||||
# if not is_py3: print >> sys.stderr, name
|
||||
# print('getattr', name, file=sys.stderr)
|
||||
return partial(self._workaround, force_unicode(name))
|
||||
return partial(self._workaround, name)
|
||||
|
||||
def _workaround(self, name, *args, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import re
|
||||
import inspect
|
||||
|
||||
from jedi._compatibility import find_module, cast_path, force_unicode, \
|
||||
from jedi._compatibility import find_module, cast_path, \
|
||||
all_suffixes
|
||||
from jedi.inference.compiled import access
|
||||
from jedi import debug
|
||||
@@ -44,7 +44,7 @@ def get_module_info(inference_state, sys_path=None, full_name=None, **kwargs):
|
||||
|
||||
|
||||
def get_builtin_module_names(inference_state):
|
||||
return list(map(force_unicode, sys.builtin_module_names))
|
||||
return sys.builtin_module_names
|
||||
|
||||
|
||||
def _test_raise_error(inference_state, exception_type):
|
||||
|
||||
@@ -7,7 +7,7 @@ from inspect import Parameter
|
||||
|
||||
from jedi import debug
|
||||
from jedi.inference.utils import to_list
|
||||
from jedi._compatibility import force_unicode, cast_path
|
||||
from jedi._compatibility import cast_path
|
||||
from jedi.cache import memoize_method
|
||||
from jedi.inference.filters import AbstractFilter
|
||||
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
||||
@@ -30,7 +30,7 @@ class CheckAttribute(object):
|
||||
def __call__(self, func):
|
||||
self.func = func
|
||||
if self.check_name is None:
|
||||
self.check_name = force_unicode(func.__name__[2:])
|
||||
self.check_name = func.__name__[2:]
|
||||
return self
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
@@ -457,9 +457,6 @@ class CompiledValueFilter(AbstractFilter):
|
||||
"""
|
||||
To remove quite a few access calls we introduced the callback here.
|
||||
"""
|
||||
# Always use unicode objects in Python 2 from here.
|
||||
name = force_unicode(name)
|
||||
|
||||
if self._inference_state.allow_descriptor_getattr:
|
||||
pass
|
||||
|
||||
@@ -535,7 +532,6 @@ def _parse_function_doc(doc):
|
||||
TODO docstrings like utime(path, (atime, mtime)) and a(b [, b]) -> None
|
||||
TODO docstrings like 'tuple of integers'
|
||||
"""
|
||||
doc = force_unicode(doc)
|
||||
# parse round parentheses: def func(a, (b,c))
|
||||
try:
|
||||
count = 0
|
||||
|
||||
@@ -10,7 +10,6 @@ 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
|
||||
@@ -63,7 +62,7 @@ def _infer_annotation_string(context, string, index=None):
|
||||
def _get_forward_reference_node(context, string):
|
||||
try:
|
||||
new_node = context.inference_state.grammar.parse(
|
||||
force_unicode(string),
|
||||
string,
|
||||
start_symbol='eval_input',
|
||||
error_recovery=False
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from jedi._compatibility import unicode, force_unicode
|
||||
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,9 +40,6 @@ class TypeVarClass(BaseTypingValue):
|
||||
return None
|
||||
else:
|
||||
safe_value = method(default=None)
|
||||
if self.inference_state.environment.version_info.major == 2:
|
||||
if isinstance(safe_value, bytes):
|
||||
return force_unicode(safe_value)
|
||||
if isinstance(safe_value, (str, unicode)):
|
||||
return safe_value
|
||||
return None
|
||||
|
||||
@@ -13,7 +13,7 @@ import os
|
||||
from parso.python import tree
|
||||
from parso.tree import search_ancestor
|
||||
|
||||
from jedi._compatibility import ImplicitNSInfo, force_unicode
|
||||
from jedi._compatibility import ImplicitNSInfo
|
||||
from jedi import debug
|
||||
from jedi import settings
|
||||
from jedi.file_io import FolderIO
|
||||
@@ -208,7 +208,7 @@ class Importer(object):
|
||||
# somewhere out of the filesystem.
|
||||
self._infer_possible = False
|
||||
else:
|
||||
self._fixed_sys_path = [force_unicode(base_directory)]
|
||||
self._fixed_sys_path = [base_directory]
|
||||
|
||||
if base_import_path is None:
|
||||
if import_path:
|
||||
@@ -329,7 +329,7 @@ def import_module_by_names(inference_state, import_names, sys_path=None,
|
||||
sys_path = inference_state.get_sys_path()
|
||||
|
||||
str_import_names = tuple(
|
||||
force_unicode(i.value if isinstance(i, tree.Name) else i)
|
||||
i.value if isinstance(i, tree.Name) else i
|
||||
for i in import_names
|
||||
)
|
||||
value_set = [None]
|
||||
|
||||
@@ -5,7 +5,7 @@ import copy
|
||||
|
||||
from parso.python import tree
|
||||
|
||||
from jedi._compatibility import force_unicode, unicode
|
||||
from jedi._compatibility import unicode
|
||||
from jedi import debug
|
||||
from jedi import parser_utils
|
||||
from jedi.inference.base_value import ValueSet, NO_VALUES, ContextualizedNode, \
|
||||
@@ -567,7 +567,7 @@ def _is_tuple(value):
|
||||
|
||||
|
||||
def _bool_to_value(inference_state, bool_):
|
||||
return compiled.builtin_from_name(inference_state, force_unicode(str(bool_)))
|
||||
return compiled.builtin_from_name(inference_state, str(bool_))
|
||||
|
||||
|
||||
def _get_tuple_ints(value):
|
||||
@@ -593,7 +593,7 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
|
||||
if isinstance(operator, unicode):
|
||||
str_operator = operator
|
||||
else:
|
||||
str_operator = force_unicode(str(operator.value))
|
||||
str_operator = str(operator.value)
|
||||
|
||||
if str_operator == '*':
|
||||
# for iterables, ignore * operations
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from jedi._compatibility import unicode, force_unicode, all_suffixes
|
||||
from jedi._compatibility import unicode, all_suffixes
|
||||
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
|
||||
@@ -25,7 +25,6 @@ def _abs_path(module_context, path):
|
||||
return None
|
||||
|
||||
base_dir = os.path.dirname(module_path)
|
||||
path = force_unicode(path)
|
||||
return os.path.abspath(os.path.join(base_dir, path))
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ iterators in general.
|
||||
"""
|
||||
import sys
|
||||
|
||||
from jedi._compatibility import force_unicode, is_py3
|
||||
from jedi._compatibility import is_py3
|
||||
from jedi.inference import compiled
|
||||
from jedi.inference import analysis
|
||||
from jedi.inference.lazy_value import LazyKnownValue, LazyKnownValues, \
|
||||
@@ -532,21 +532,6 @@ class FakeDict(_DictMixin, Sequence, _DictKeyMixin):
|
||||
yield LazyKnownValue(compiled.create_simple_object(self.inference_state, key))
|
||||
|
||||
def py__simple_getitem__(self, index):
|
||||
if is_py3 and self.inference_state.environment.version_info.major == 2:
|
||||
# In Python 2 bytes and unicode compare.
|
||||
if isinstance(index, bytes):
|
||||
index_unicode = force_unicode(index)
|
||||
try:
|
||||
return self._dct[index_unicode].infer()
|
||||
except KeyError:
|
||||
pass
|
||||
elif isinstance(index, str):
|
||||
index_bytes = index.encode('utf-8')
|
||||
try:
|
||||
return self._dct[index_bytes].infer()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
with reraise_getitem_errors(KeyError, TypeError):
|
||||
lazy_value = self._dct[index]
|
||||
return lazy_value.infer()
|
||||
|
||||
@@ -8,8 +8,6 @@ from parso.python import tree
|
||||
from parso.cache import parser_cache
|
||||
from parso import split_lines
|
||||
|
||||
from jedi._compatibility import force_unicode
|
||||
|
||||
_EXECUTE_NODES = {'funcdef', 'classdef', 'import_from', 'import_name', 'test',
|
||||
'or_test', 'and_test', 'not_test', 'comparison', 'expr',
|
||||
'xor_expr', 'and_expr', 'shift_expr', 'arith_expr',
|
||||
@@ -103,10 +101,7 @@ def clean_scope_docstring(scope_node):
|
||||
# leaves anymore that might be part of the docstring. A
|
||||
# docstring can also look like this: ``'foo' 'bar'
|
||||
# Returns a literal cleaned version of the ``Token``.
|
||||
cleaned = cleandoc(safe_literal_eval(node.value))
|
||||
# Since we want the docstr output to be always unicode, just
|
||||
# force it.
|
||||
return force_unicode(cleaned)
|
||||
return cleandoc(safe_literal_eval(node.value))
|
||||
return ''
|
||||
|
||||
|
||||
@@ -118,10 +113,7 @@ def find_statement_documentation(tree_node):
|
||||
if maybe_string.type == 'simple_stmt':
|
||||
maybe_string = maybe_string.children[0]
|
||||
if maybe_string.type == 'string':
|
||||
cleaned = cleandoc(safe_literal_eval(maybe_string.value))
|
||||
# Since we want the docstr output to be always unicode, just
|
||||
# force it.
|
||||
return force_unicode(cleaned)
|
||||
return cleandoc(safe_literal_eval(maybe_string.value))
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import parso
|
||||
import os
|
||||
from inspect import Parameter
|
||||
|
||||
from jedi._compatibility import force_unicode
|
||||
from jedi import debug
|
||||
from jedi.inference.utils import safe_property
|
||||
from jedi.inference.helpers import get_str_or_none
|
||||
@@ -209,7 +208,7 @@ def builtins_getattr(objects, names, defaults=None):
|
||||
debug.warning('getattr called without str')
|
||||
continue
|
||||
else:
|
||||
return value.py__getattribute__(force_unicode(string))
|
||||
return value.py__getattribute__(string)
|
||||
return NO_VALUES
|
||||
|
||||
|
||||
@@ -330,7 +329,7 @@ def builtins_isinstance(objects, types, arguments, inference_state):
|
||||
analysis.add(lazy_value.context, 'type-error-isinstance', node, message)
|
||||
|
||||
return ValueSet(
|
||||
compiled.builtin_from_name(inference_state, force_unicode(str(b)))
|
||||
compiled.builtin_from_name(inference_state, str(b))
|
||||
for b in bool_results
|
||||
)
|
||||
|
||||
@@ -431,7 +430,7 @@ def collections_namedtuple(value, arguments, callback):
|
||||
for c in _follow_param(inference_state, arguments, 0):
|
||||
x = get_str_or_none(c)
|
||||
if x is not None:
|
||||
name = force_unicode(x)
|
||||
name = x
|
||||
break
|
||||
|
||||
# TODO here we only use one of the types, we should use all.
|
||||
@@ -441,10 +440,10 @@ def collections_namedtuple(value, arguments, callback):
|
||||
_fields = list(param_values)[0]
|
||||
string = get_str_or_none(_fields)
|
||||
if string is not None:
|
||||
fields = force_unicode(string).replace(',', ' ').split()
|
||||
fields = string.replace(',', ' ').split()
|
||||
elif isinstance(_fields, iterable.Sequence):
|
||||
fields = [
|
||||
force_unicode(get_str_or_none(v))
|
||||
get_str_or_none(v)
|
||||
for lazy_value in _fields.py__iter__()
|
||||
for v in lazy_value.infer()
|
||||
]
|
||||
@@ -745,7 +744,7 @@ def _os_path_join(args_set, callback):
|
||||
break
|
||||
if not is_first:
|
||||
string += os.path.sep
|
||||
string += force_unicode(s)
|
||||
string += s
|
||||
is_first = False
|
||||
else:
|
||||
return ValueSet([compiled.create_simple_object(sequence.inference_state, string)])
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
from textwrap import dedent
|
||||
|
||||
from jedi._compatibility import force_unicode
|
||||
from jedi.inference.sys_path import _get_parent_dir_with_file, \
|
||||
_get_buildout_script_paths, check_sys_path_modifications
|
||||
|
||||
@@ -79,6 +78,5 @@ def test_path_from_sys_path_assignment(Script):
|
||||
sys.exit(important_package.main())""")
|
||||
|
||||
paths = check_module_test(Script, code)
|
||||
paths = list(map(force_unicode, paths))
|
||||
assert 1 not in paths
|
||||
assert '/home/test/.buildout/eggs/important_package.egg' in paths
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from jedi._compatibility import force_unicode
|
||||
|
||||
|
||||
def test_module_attributes(Script):
|
||||
def_, = Script('__name__').complete()
|
||||
assert def_.name == '__name__'
|
||||
@@ -13,9 +10,9 @@ def test_module_attributes(Script):
|
||||
def test_module__file__(Script, environment):
|
||||
assert not Script('__file__').infer()
|
||||
def_, = Script('__file__', path='example.py').infer()
|
||||
value = force_unicode(def_._name._value.get_safe_value())
|
||||
value = def_._name._value.get_safe_value()
|
||||
assert value.endswith('example.py')
|
||||
|
||||
def_, = Script('import antigravity; antigravity.__file__').infer()
|
||||
value = force_unicode(def_._name._value.get_safe_value())
|
||||
value = def_._name._value.get_safe_value()
|
||||
assert value.endswith('.py')
|
||||
|
||||
Reference in New Issue
Block a user