mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
cleanup
This commit is contained in:
@@ -4,7 +4,7 @@ python versions.
|
|||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
is_py3k = sys.hexversion >= 0x03000000
|
is_py3k = sys.hexversion >= 0x03000000
|
||||||
|
|
||||||
is_py25 = sys.hexversion < 0x02060000
|
is_py25 = sys.hexversion < 0x02060000
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
# hasattr function used because python
|
# hasattr function used because python
|
||||||
if is_py3k:
|
if is_py3k:
|
||||||
hasattr = hasattr
|
hasattr = hasattr
|
||||||
else:
|
else:
|
||||||
@@ -93,6 +93,7 @@ else:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Python3Method(object):
|
class Python3Method(object):
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
self.func = func
|
self.func = func
|
||||||
@@ -109,6 +110,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
reduce = reduce
|
reduce = reduce
|
||||||
|
|
||||||
|
|
||||||
def use_metaclass(meta, *bases):
|
def use_metaclass(meta, *bases):
|
||||||
""" Create a class with a metaclass. """
|
""" Create a class with a metaclass. """
|
||||||
if not bases:
|
if not bases:
|
||||||
@@ -120,6 +122,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
# python 2.5 doesn't have this method
|
# python 2.5 doesn't have this method
|
||||||
import string
|
import string
|
||||||
|
|
||||||
def cleandoc(doc):
|
def cleandoc(doc):
|
||||||
"""Clean up indentation from docstrings.
|
"""Clean up indentation from docstrings.
|
||||||
|
|
||||||
@@ -141,7 +144,8 @@ except ImportError:
|
|||||||
if lines:
|
if lines:
|
||||||
lines[0] = lines[0].lstrip()
|
lines[0] = lines[0].lstrip()
|
||||||
if margin < sys.maxint:
|
if margin < sys.maxint:
|
||||||
for i in range(1, len(lines)): lines[i] = lines[i][margin:]
|
for i in range(1, len(lines)):
|
||||||
|
lines[i] = lines[i][margin:]
|
||||||
# Remove any trailing or leading blank lines.
|
# Remove any trailing or leading blank lines.
|
||||||
while lines and not lines[-1]:
|
while lines and not lines[-1]:
|
||||||
lines.pop()
|
lines.pop()
|
||||||
|
|||||||
@@ -993,7 +993,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
# class renames
|
# class renames
|
||||||
add = [InstanceElement(check_instance, a, True)
|
add = [InstanceElement(check_instance, a, True)
|
||||||
if isinstance(a, (Function, parsing.Function))
|
if isinstance(a, (Function, parsing.Function))
|
||||||
else a for a in add ]
|
else a for a in add]
|
||||||
res_new += add
|
res_new += add
|
||||||
else:
|
else:
|
||||||
if isinstance(r, parsing.Class):
|
if isinstance(r, parsing.Class):
|
||||||
@@ -1030,8 +1030,6 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
no_break_scope = False
|
no_break_scope = False
|
||||||
#if isinstance(scope, InstanceElement) and scope.var == name.parent().parent():
|
|
||||||
#name = InstanceElement(scope.instance, name)
|
|
||||||
par = name.parent()
|
par = name.parent()
|
||||||
|
|
||||||
if par.isinstance(parsing.Flow):
|
if par.isinstance(parsing.Flow):
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Completion(object):
|
|||||||
append = ''
|
append = ''
|
||||||
funcs = (parsing.Function, evaluate.Function)
|
funcs = (parsing.Function, evaluate.Function)
|
||||||
if settings.add_bracket_after_function \
|
if settings.add_bracket_after_function \
|
||||||
and isinstance( self._completion_parent, funcs):
|
and isinstance(self._completion_parent, funcs):
|
||||||
append = '('
|
append = '('
|
||||||
|
|
||||||
if settings.add_dot_after_module:
|
if settings.add_dot_after_module:
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ class ExecutionRecursionDecorator(object):
|
|||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def __call__(self, execution, evaluate_generator=False):
|
def __call__(self, execution, evaluate_generator=False):
|
||||||
#print execution, self.recursion_level, self.execution_count, len(self.execution_funcs), a
|
debug.dbg('Execution recursions: ', execution, self.recursion_level,
|
||||||
|
self.execution_count, len(self.execution_funcs))
|
||||||
if self.check_recursion(execution, evaluate_generator):
|
if self.check_recursion(execution, evaluate_generator):
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class TestRegression(unittest.TestCase):
|
|||||||
"A.different_line"
|
"A.different_line"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
in_name = 2, 9
|
in_name = 2, 9
|
||||||
under_score = 2, 8
|
under_score = 2, 8
|
||||||
cls = 2, 7
|
cls = 2, 7
|
||||||
@@ -55,29 +54,29 @@ class TestRegression(unittest.TestCase):
|
|||||||
self.assertRaises(functions.NotFoundError, get_def, cls)
|
self.assertRaises(functions.NotFoundError, get_def, cls)
|
||||||
|
|
||||||
def test_keyword_doc(self):
|
def test_keyword_doc(self):
|
||||||
r = list(self.get_def("or", (1,1)))
|
r = list(self.get_def("or", (1, 1)))
|
||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
if not is_py25:
|
if not is_py25:
|
||||||
assert len(r[0].doc) > 100
|
assert len(r[0].doc) > 100
|
||||||
|
|
||||||
r = list(self.get_def("asfdasfd", (1,1)))
|
r = list(self.get_def("asfdasfd", (1, 1)))
|
||||||
assert len(r) == 0
|
assert len(r) == 0
|
||||||
|
|
||||||
def test_operator_doc(self):
|
def test_operator_doc(self):
|
||||||
r = list(self.get_def("a == b", (1,3)))
|
r = list(self.get_def("a == b", (1, 3)))
|
||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
if not is_py25:
|
if not is_py25:
|
||||||
assert len(r[0].doc) > 100
|
assert len(r[0].doc) > 100
|
||||||
|
|
||||||
def test_get_definition_at_zero(self):
|
def test_get_definition_at_zero(self):
|
||||||
assert self.get_def("a", (1,1)) == set()
|
assert self.get_def("a", (1, 1)) == set()
|
||||||
s = self.get_def("str", (1,1))
|
s = self.get_def("str", (1, 1))
|
||||||
assert len(s) == 1
|
assert len(s) == 1
|
||||||
assert list(s)[0].description == 'class str'
|
assert list(s)[0].description == 'class str'
|
||||||
assert self.get_def("", (1,0)) == set()
|
assert self.get_def("", (1, 0)) == set()
|
||||||
|
|
||||||
def test_complete_at_zero(self):
|
def test_complete_at_zero(self):
|
||||||
s = self.complete("str", (1,3))
|
s = self.complete("str", (1, 3))
|
||||||
assert len(s) == 1
|
assert len(s) == 1
|
||||||
assert list(s)[0].word == 'str'
|
assert list(s)[0].word == 'str'
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import traceback
|
|||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from _compatibility import unicode, BytesIO, reduce, literal_eval
|
from _compatibility import unicode, BytesIO, reduce, literal_eval, is_py25
|
||||||
|
|
||||||
import functions
|
import functions
|
||||||
import debug
|
import debug
|
||||||
@@ -185,8 +185,7 @@ def test_dir(completion_test_dir, thirdparty=False):
|
|||||||
if f_name.endswith(".py") and (not test_files or files_to_execute):
|
if f_name.endswith(".py") and (not test_files or files_to_execute):
|
||||||
# for python2.5 certain tests are not being done, because it
|
# for python2.5 certain tests are not being done, because it
|
||||||
# only has these features partially.
|
# only has these features partially.
|
||||||
if sys.hexversion < 0x02060000 \
|
if is_py25 and f_name in ['generators.py', 'types.py']:
|
||||||
and f_name in ['generators.py', 'types.py']:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if thirdparty:
|
if thirdparty:
|
||||||
|
|||||||
Reference in New Issue
Block a user