Start using a lot more unicode literals for Python 2

This commit is contained in:
Dave Halter
2017-12-24 03:11:28 +01:00
parent 1f4e0dd22e
commit 5a06ea2699
11 changed files with 22 additions and 22 deletions

View File

@@ -220,14 +220,14 @@ except AttributeError:
encoding = 'ascii' encoding = 'ascii'
def u(string): def u(string, errors='strict'):
"""Cast to unicode DAMMIT! """Cast to unicode DAMMIT!
Written because Python2 repr always implicitly casts to a string, so we 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 have to cast back to a unicode (and we now that we always deal with valid
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 str(string, encoding='UTF-8') return unicode(string, encoding='UTF-8', errors=errors)
return string return string

View File

@@ -73,7 +73,7 @@ keywords_only_valid_as_leaf = (
class KeywordName(AbstractNameDefinition): class KeywordName(AbstractNameDefinition):
api_type = 'keyword' api_type = u'keyword'
def __init__(self, evaluator, name): def __init__(self, evaluator, name):
self.evaluator = evaluator self.evaluator = evaluator
@@ -88,7 +88,7 @@ class KeywordName(AbstractNameDefinition):
class Keyword(object): class Keyword(object):
api_type = 'keyword' api_type = u'keyword'
def __init__(self, evaluator, name, pos): def __init__(self, evaluator, name, pos):
self.name = KeywordName(evaluator, name) self.name = KeywordName(evaluator, name)

View File

@@ -5,7 +5,7 @@ import operator as op
from collections import namedtuple from collections import namedtuple
from jedi import debug 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.compiled.getattr_static import getattr_static
from jedi.evaluate.utils import dotted_from_fs_path from jedi.evaluate.utils import dotted_from_fs_path
@@ -192,7 +192,7 @@ class DirectObjectAccess(object):
return None return None
def py__doc__(self, include_call_signature=False): 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): def py__name__(self):
if not _is_class_instance(self._obj) or \ if not _is_class_instance(self._obj) or \
@@ -300,14 +300,14 @@ class DirectObjectAccess(object):
def get_api_type(self): def get_api_type(self):
obj = self._obj obj = self._obj
if self.is_class(): if self.is_class():
return 'class' return u'class'
elif inspect.ismodule(obj): elif inspect.ismodule(obj):
return 'module' return u'module'
elif inspect.isbuiltin(obj) or inspect.ismethod(obj) \ elif inspect.isbuiltin(obj) or inspect.ismethod(obj) \
or inspect.ismethoddescriptor(obj) or inspect.isfunction(obj): or inspect.ismethoddescriptor(obj) or inspect.isfunction(obj):
return 'function' return u'function'
# Everything else... # Everything else...
return 'instance' return u'instance'
def get_access_path_tuples(self): def get_access_path_tuples(self):
return [ return [

View File

@@ -236,7 +236,7 @@ class CompiledName(AbstractNameDefinition):
class SignatureParamName(AbstractNameDefinition): class SignatureParamName(AbstractNameDefinition):
api_type = 'param' api_type = u'param'
def __init__(self, compiled_obj, signature_param): def __init__(self, compiled_obj, signature_param):
self.parent_context = compiled_obj.parent_context self.parent_context = compiled_obj.parent_context
@@ -259,7 +259,7 @@ class SignatureParamName(AbstractNameDefinition):
class UnresolvableParamName(AbstractNameDefinition): class UnresolvableParamName(AbstractNameDefinition):
api_type = 'param' api_type = u'param'
def __init__(self, compiled_obj, name): def __init__(self, compiled_obj, name):
self.parent_context = compiled_obj.parent_context self.parent_context = compiled_obj.parent_context

View File

@@ -39,7 +39,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, TreeContext)):
""" """
Needed because of decorators. Decorators are evaluated here. Needed because of decorators. Decorators are evaluated here.
""" """
api_type = 'function' api_type = u'function'
def __init__(self, evaluator, parent_context, funcdef): def __init__(self, evaluator, parent_context, funcdef):
""" This should not be called directly """ """ This should not be called directly """

View File

@@ -39,7 +39,7 @@ class AbstractInstanceContext(Context):
""" """
This class is used to evaluate instances. This class is used to evaluate instances.
""" """
api_type = 'instance' api_type = u'instance'
function_execution_cls = InstanceFunctionExecution function_execution_cls = InstanceFunctionExecution
def __init__(self, evaluator, parent_context, class_context, var_args): def __init__(self, evaluator, parent_context, class_context, var_args):

View File

@@ -41,7 +41,7 @@ from jedi.parser_utils import get_comp_fors
class AbstractIterable(Context): class AbstractIterable(Context):
builtin_methods = {} builtin_methods = {}
api_type = 'instance' api_type = u'instance'
def __init__(self, evaluator): def __init__(self, evaluator):
super(AbstractIterable, self).__init__(evaluator, evaluator.builtins_module) super(AbstractIterable, self).__init__(evaluator, evaluator.builtins_module)

View File

@@ -89,7 +89,7 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
This class is not only important to extend `tree.Class`, it is also a 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). 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): def __init__(self, evaluator, parent_context, classdef):
super(ClassContext, self).__init__(evaluator, parent_context=parent_context) super(ClassContext, self).__init__(evaluator, parent_context=parent_context)

View File

@@ -18,7 +18,7 @@ class _ModuleAttributeName(AbstractNameDefinition):
""" """
For module attributes like __file__, __str__ and so on. For module attributes like __file__, __str__ and so on.
""" """
api_type = 'instance' api_type = u'instance'
def __init__(self, parent_module, string_name): def __init__(self, parent_module, string_name):
self.parent_context = parent_module self.parent_context = parent_module
@@ -42,7 +42,7 @@ class ModuleName(ContextNameMixin, AbstractNameDefinition):
class ModuleContext(use_metaclass(CachedMetaClass, TreeContext)): class ModuleContext(use_metaclass(CachedMetaClass, TreeContext)):
api_type = 'module' api_type = u'module'
parent_context = None parent_context = None
def __init__(self, evaluator, module_node, path): def __init__(self, evaluator, module_node, path):

View File

@@ -27,7 +27,7 @@ class ImplicitNamespaceContext(TreeContext):
""" """
Provides support for implicit namespace packages Provides support for implicit namespace packages
""" """
api_type = 'module' api_type = u'module'
parent_context = None parent_context = None
def __init__(self, evaluator, fullname, paths): def __init__(self, evaluator, fullname, paths):

View File

@@ -108,7 +108,7 @@ class TreeNameDefinition(AbstractTreeName):
class ParamName(AbstractTreeName): class ParamName(AbstractTreeName):
api_type = 'param' api_type = u'param'
def __init__(self, parent_context, tree_name): def __init__(self, parent_context, tree_name):
self.parent_context = parent_context self.parent_context = parent_context
@@ -281,7 +281,7 @@ class DictFilter(AbstractFilter):
class _BuiltinMappedMethod(Context): class _BuiltinMappedMethod(Context):
"""``Generator.__next__`` ``dict.values`` methods and so on.""" """``Generator.__next__`` ``dict.values`` methods and so on."""
api_type = 'function' api_type = u'function'
def __init__(self, builtin_context, method, builtin_func): def __init__(self, builtin_context, method, builtin_func):
super(_BuiltinMappedMethod, self).__init__( super(_BuiltinMappedMethod, self).__init__(
@@ -304,7 +304,7 @@ class SpecialMethodFilter(DictFilter):
classes like Generator (for __next__, etc). classes like Generator (for __next__, etc).
""" """
class SpecialMethodName(AbstractNameDefinition): class SpecialMethodName(AbstractNameDefinition):
api_type = 'function' api_type = u'function'
def __init__(self, parent_context, string_name, callable_, builtin_context): def __init__(self, parent_context, string_name, callable_, builtin_context):
self.parent_context = parent_context self.parent_context = parent_context