forked from VimPlug/jedi
Start using a lot more unicode literals for Python 2
This commit is contained in:
@@ -220,14 +220,14 @@ except AttributeError:
|
||||
encoding = 'ascii'
|
||||
|
||||
|
||||
def u(string):
|
||||
def u(string, errors='strict'):
|
||||
"""Cast to unicode DAMMIT!
|
||||
Written because Python2 repr always implicitly casts to a string, so we
|
||||
have to cast back to a unicode (and we now that we always deal with valid
|
||||
unicode, because we check that in the beginning).
|
||||
"""
|
||||
if isinstance(string, bytes):
|
||||
return str(string, encoding='UTF-8')
|
||||
return unicode(string, encoding='UTF-8', errors=errors)
|
||||
return string
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ keywords_only_valid_as_leaf = (
|
||||
|
||||
|
||||
class KeywordName(AbstractNameDefinition):
|
||||
api_type = 'keyword'
|
||||
api_type = u'keyword'
|
||||
|
||||
def __init__(self, evaluator, name):
|
||||
self.evaluator = evaluator
|
||||
@@ -88,7 +88,7 @@ class KeywordName(AbstractNameDefinition):
|
||||
|
||||
|
||||
class Keyword(object):
|
||||
api_type = 'keyword'
|
||||
api_type = u'keyword'
|
||||
|
||||
def __init__(self, evaluator, name, pos):
|
||||
self.name = KeywordName(evaluator, name)
|
||||
|
||||
@@ -5,7 +5,7 @@ import operator as op
|
||||
from collections import namedtuple
|
||||
|
||||
from jedi import debug
|
||||
from jedi._compatibility import unicode, is_py3, is_py34, builtins, py_version
|
||||
from jedi._compatibility import unicode, is_py3, is_py34, builtins, py_version, u
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
from jedi.evaluate.utils import dotted_from_fs_path
|
||||
|
||||
@@ -192,7 +192,7 @@ class DirectObjectAccess(object):
|
||||
return None
|
||||
|
||||
def py__doc__(self, include_call_signature=False):
|
||||
return inspect.getdoc(self._obj) or ''
|
||||
return u(inspect.getdoc(self._obj), errors='replace') or u''
|
||||
|
||||
def py__name__(self):
|
||||
if not _is_class_instance(self._obj) or \
|
||||
@@ -300,14 +300,14 @@ class DirectObjectAccess(object):
|
||||
def get_api_type(self):
|
||||
obj = self._obj
|
||||
if self.is_class():
|
||||
return 'class'
|
||||
return u'class'
|
||||
elif inspect.ismodule(obj):
|
||||
return 'module'
|
||||
return u'module'
|
||||
elif inspect.isbuiltin(obj) or inspect.ismethod(obj) \
|
||||
or inspect.ismethoddescriptor(obj) or inspect.isfunction(obj):
|
||||
return 'function'
|
||||
return u'function'
|
||||
# Everything else...
|
||||
return 'instance'
|
||||
return u'instance'
|
||||
|
||||
def get_access_path_tuples(self):
|
||||
return [
|
||||
|
||||
@@ -236,7 +236,7 @@ class CompiledName(AbstractNameDefinition):
|
||||
|
||||
|
||||
class SignatureParamName(AbstractNameDefinition):
|
||||
api_type = 'param'
|
||||
api_type = u'param'
|
||||
|
||||
def __init__(self, compiled_obj, signature_param):
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
@@ -259,7 +259,7 @@ class SignatureParamName(AbstractNameDefinition):
|
||||
|
||||
|
||||
class UnresolvableParamName(AbstractNameDefinition):
|
||||
api_type = 'param'
|
||||
api_type = u'param'
|
||||
|
||||
def __init__(self, compiled_obj, name):
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
|
||||
@@ -39,7 +39,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
"""
|
||||
Needed because of decorators. Decorators are evaluated here.
|
||||
"""
|
||||
api_type = 'function'
|
||||
api_type = u'function'
|
||||
|
||||
def __init__(self, evaluator, parent_context, funcdef):
|
||||
""" This should not be called directly """
|
||||
|
||||
@@ -39,7 +39,7 @@ class AbstractInstanceContext(Context):
|
||||
"""
|
||||
This class is used to evaluate instances.
|
||||
"""
|
||||
api_type = 'instance'
|
||||
api_type = u'instance'
|
||||
function_execution_cls = InstanceFunctionExecution
|
||||
|
||||
def __init__(self, evaluator, parent_context, class_context, var_args):
|
||||
|
||||
@@ -41,7 +41,7 @@ from jedi.parser_utils import get_comp_fors
|
||||
|
||||
class AbstractIterable(Context):
|
||||
builtin_methods = {}
|
||||
api_type = 'instance'
|
||||
api_type = u'instance'
|
||||
|
||||
def __init__(self, evaluator):
|
||||
super(AbstractIterable, self).__init__(evaluator, evaluator.builtins_module)
|
||||
|
||||
@@ -89,7 +89,7 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
This class is not only important to extend `tree.Class`, it is also a
|
||||
important for descriptors (if the descriptor methods are evaluated or not).
|
||||
"""
|
||||
api_type = 'class'
|
||||
api_type = u'class'
|
||||
|
||||
def __init__(self, evaluator, parent_context, classdef):
|
||||
super(ClassContext, self).__init__(evaluator, parent_context=parent_context)
|
||||
|
||||
@@ -18,7 +18,7 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
||||
"""
|
||||
For module attributes like __file__, __str__ and so on.
|
||||
"""
|
||||
api_type = 'instance'
|
||||
api_type = u'instance'
|
||||
|
||||
def __init__(self, parent_module, string_name):
|
||||
self.parent_context = parent_module
|
||||
@@ -42,7 +42,7 @@ class ModuleName(ContextNameMixin, AbstractNameDefinition):
|
||||
|
||||
|
||||
class ModuleContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
api_type = 'module'
|
||||
api_type = u'module'
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, evaluator, module_node, path):
|
||||
|
||||
@@ -27,7 +27,7 @@ class ImplicitNamespaceContext(TreeContext):
|
||||
"""
|
||||
Provides support for implicit namespace packages
|
||||
"""
|
||||
api_type = 'module'
|
||||
api_type = u'module'
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, evaluator, fullname, paths):
|
||||
|
||||
@@ -108,7 +108,7 @@ class TreeNameDefinition(AbstractTreeName):
|
||||
|
||||
|
||||
class ParamName(AbstractTreeName):
|
||||
api_type = 'param'
|
||||
api_type = u'param'
|
||||
|
||||
def __init__(self, parent_context, tree_name):
|
||||
self.parent_context = parent_context
|
||||
@@ -281,7 +281,7 @@ class DictFilter(AbstractFilter):
|
||||
|
||||
class _BuiltinMappedMethod(Context):
|
||||
"""``Generator.__next__`` ``dict.values`` methods and so on."""
|
||||
api_type = 'function'
|
||||
api_type = u'function'
|
||||
|
||||
def __init__(self, builtin_context, method, builtin_func):
|
||||
super(_BuiltinMappedMethod, self).__init__(
|
||||
@@ -304,7 +304,7 @@ class SpecialMethodFilter(DictFilter):
|
||||
classes like Generator (for __next__, etc).
|
||||
"""
|
||||
class SpecialMethodName(AbstractNameDefinition):
|
||||
api_type = 'function'
|
||||
api_type = u'function'
|
||||
|
||||
def __init__(self, parent_context, string_name, callable_, builtin_context):
|
||||
self.parent_context = parent_context
|
||||
|
||||
Reference in New Issue
Block a user