forked from VimPlug/jedi
Remove the u() unicode function
This commit is contained in:
@@ -134,18 +134,7 @@ class ImplicitNSInfo(object):
|
||||
self.paths = paths
|
||||
|
||||
|
||||
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', errors=errors)
|
||||
return string
|
||||
|
||||
|
||||
def cast_path(obj):
|
||||
def cast_path(string):
|
||||
"""
|
||||
Take a bytes or str path and cast it to unicode.
|
||||
|
||||
@@ -156,7 +145,9 @@ def cast_path(obj):
|
||||
Since this just really complicates everything and Python 2.7 will be EOL
|
||||
soon anyway, just go with always strings.
|
||||
"""
|
||||
return u(obj, errors='replace')
|
||||
if isinstance(string, bytes):
|
||||
return str(string, encoding='UTF-8', errors='replace')
|
||||
return string
|
||||
|
||||
|
||||
def pickle_load(file):
|
||||
|
||||
@@ -11,7 +11,6 @@ from inspect import Parameter
|
||||
from parso.python.parser import Parser
|
||||
from parso.python import tree
|
||||
|
||||
from jedi._compatibility import u
|
||||
from jedi.inference.base_value import NO_VALUES
|
||||
from jedi.inference.syntax_tree import infer_atom
|
||||
from jedi.inference.helpers import infer_call_of_leaf
|
||||
@@ -85,18 +84,18 @@ def _get_code_for_stack(code_lines, leaf, position):
|
||||
# If we're not on a comment simply get the previous leaf and proceed.
|
||||
leaf = leaf.get_previous_leaf()
|
||||
if leaf is None:
|
||||
return u('') # At the beginning of the file.
|
||||
return '' # At the beginning of the file.
|
||||
|
||||
is_after_newline = leaf.type == 'newline'
|
||||
while leaf.type == 'newline':
|
||||
leaf = leaf.get_previous_leaf()
|
||||
if leaf is None:
|
||||
return u('')
|
||||
return ''
|
||||
|
||||
if leaf.type == 'error_leaf' or leaf.type == 'string':
|
||||
if leaf.start_pos[0] < position[0]:
|
||||
# On a different line, we just begin anew.
|
||||
return u('')
|
||||
return ''
|
||||
|
||||
# Error leafs cannot be parsed, completion in strings is also
|
||||
# impossible.
|
||||
@@ -112,7 +111,7 @@ def _get_code_for_stack(code_lines, leaf, position):
|
||||
if user_stmt.start_pos[1] > position[1]:
|
||||
# This means that it's actually a dedent and that means that we
|
||||
# start without value (part of a suite).
|
||||
return u('')
|
||||
return ''
|
||||
|
||||
# This is basically getting the relevant lines.
|
||||
return _get_code(code_lines, user_stmt.get_start_pos_of_prefix(), position)
|
||||
|
||||
@@ -2,8 +2,6 @@ import os
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
from jedi._compatibility import u
|
||||
|
||||
_inited = False
|
||||
|
||||
|
||||
@@ -104,7 +102,7 @@ def dbg(message, *args, color='GREEN'):
|
||||
if debug_function and enable_notice:
|
||||
i = ' ' * _debug_indent
|
||||
_lazy_colorama_init()
|
||||
debug_function(color, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
|
||||
debug_function(color, i + 'dbg: ' + message % tuple(repr(a) for a in args))
|
||||
|
||||
|
||||
def warning(message, *args, **kwargs):
|
||||
@@ -114,7 +112,7 @@ def warning(message, *args, **kwargs):
|
||||
if debug_function and enable_warning:
|
||||
i = ' ' * _debug_indent
|
||||
if format:
|
||||
message = message % tuple(u(repr(a)) for a in args)
|
||||
message = message % tuple(repr(a) for a in args)
|
||||
debug_function('RED', i + 'warning: ' + message)
|
||||
|
||||
|
||||
|
||||
@@ -438,13 +438,12 @@ def get_global_filters(context, until_position, origin_scope):
|
||||
For global name lookups. The filters will handle name resolution
|
||||
themselves, but here we gather possible filters downwards.
|
||||
|
||||
>>> from jedi._compatibility import u
|
||||
>>> from jedi import Script
|
||||
>>> script = Script(u('''
|
||||
>>> script = Script('''
|
||||
... x = ['a', 'b', 'c']
|
||||
... def func():
|
||||
... y = None
|
||||
... '''))
|
||||
... ''')
|
||||
>>> module_node = script._module_node
|
||||
>>> scope = next(module_node.iter_funcdefs())
|
||||
>>> scope
|
||||
|
||||
@@ -21,7 +21,6 @@ from textwrap import dedent
|
||||
|
||||
from parso import parse, ParserSyntaxError
|
||||
|
||||
from jedi._compatibility import u
|
||||
from jedi import debug
|
||||
from jedi.common import indent_block
|
||||
from jedi.inference.cache import inference_state_method_cache
|
||||
@@ -184,7 +183,7 @@ def _strip_rst_role(type_str):
|
||||
|
||||
|
||||
def _infer_for_statement_string(module_context, string):
|
||||
code = dedent(u("""
|
||||
code = dedent("""
|
||||
def pseudo_docstring_stuff():
|
||||
'''
|
||||
Create a pseudo function for docstring statements.
|
||||
@@ -192,7 +191,7 @@ def _infer_for_statement_string(module_context, string):
|
||||
is still a function.
|
||||
'''
|
||||
{}
|
||||
"""))
|
||||
""")
|
||||
if string is None:
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user