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