From 844e222ed57538d265b7613cb84e0c20fc3055a7 Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 6 Sep 2012 11:23:12 +0200 Subject: [PATCH] cleanup --- _compatibility.py | 10 +++++++--- evaluate.py | 4 +--- functions.py | 2 +- helpers.py | 3 ++- test/regression.py | 15 +++++++-------- test/run.py | 5 ++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/_compatibility.py b/_compatibility.py index 8536f4e6..2fe49343 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -4,7 +4,7 @@ python versions. """ import sys -is_py3k = sys.hexversion >= 0x03000000 +is_py3k = sys.hexversion >= 0x03000000 is_py25 = sys.hexversion < 0x02060000 @@ -82,7 +82,7 @@ try: except ImportError: from io import BytesIO -# hasattr function used because python +# hasattr function used because python if is_py3k: hasattr = hasattr else: @@ -93,6 +93,7 @@ else: except AttributeError: return False + class Python3Method(object): def __init__(self, func): self.func = func @@ -109,6 +110,7 @@ try: except ImportError: reduce = reduce + def use_metaclass(meta, *bases): """ Create a class with a metaclass. """ if not bases: @@ -120,6 +122,7 @@ try: except ImportError: # python 2.5 doesn't have this method import string + def cleandoc(doc): """Clean up indentation from docstrings. @@ -141,7 +144,8 @@ except ImportError: if lines: lines[0] = lines[0].lstrip() 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. while lines and not lines[-1]: lines.pop() diff --git a/evaluate.py b/evaluate.py index 11fc3ccb..2d3c51d8 100644 --- a/evaluate.py +++ b/evaluate.py @@ -993,7 +993,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False): # class renames add = [InstanceElement(check_instance, a, True) if isinstance(a, (Function, parsing.Function)) - else a for a in add ] + else a for a in add] res_new += add else: if isinstance(r, parsing.Class): @@ -1030,8 +1030,6 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False): """ result = [] no_break_scope = False - #if isinstance(scope, InstanceElement) and scope.var == name.parent().parent(): - #name = InstanceElement(scope.instance, name) par = name.parent() if par.isinstance(parsing.Flow): diff --git a/functions.py b/functions.py index 6767dcf6..0debf320 100644 --- a/functions.py +++ b/functions.py @@ -36,7 +36,7 @@ class Completion(object): append = '' funcs = (parsing.Function, evaluate.Function) if settings.add_bracket_after_function \ - and isinstance( self._completion_parent, funcs): + and isinstance(self._completion_parent, funcs): append = '(' if settings.add_dot_after_module: diff --git a/helpers.py b/helpers.py index 1b24ac68..111d7f38 100644 --- a/helpers.py +++ b/helpers.py @@ -92,7 +92,8 @@ class ExecutionRecursionDecorator(object): self.reset() 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): result = [] else: diff --git a/test/regression.py b/test/regression.py index f2cd792b..45fef560 100755 --- a/test/regression.py +++ b/test/regression.py @@ -30,7 +30,6 @@ class TestRegression(unittest.TestCase): "A.different_line" ) - in_name = 2, 9 under_score = 2, 8 cls = 2, 7 @@ -55,29 +54,29 @@ class TestRegression(unittest.TestCase): self.assertRaises(functions.NotFoundError, get_def, cls) 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 if not is_py25: 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 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 if not is_py25: assert len(r[0].doc) > 100 def test_get_definition_at_zero(self): - assert self.get_def("a", (1,1)) == set() - s = self.get_def("str", (1,1)) + assert self.get_def("a", (1, 1)) == set() + s = self.get_def("str", (1, 1)) assert len(s) == 1 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): - s = self.complete("str", (1,3)) + s = self.complete("str", (1, 3)) assert len(s) == 1 assert list(s)[0].word == 'str' diff --git a/test/run.py b/test/run.py index 3a33bc83..504bc6e2 100755 --- a/test/run.py +++ b/test/run.py @@ -7,7 +7,7 @@ import traceback os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/..') sys.path.append('.') -from _compatibility import unicode, BytesIO, reduce, literal_eval +from _compatibility import unicode, BytesIO, reduce, literal_eval, is_py25 import functions 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): # for python2.5 certain tests are not being done, because it # only has these features partially. - if sys.hexversion < 0x02060000 \ - and f_name in ['generators.py', 'types.py']: + if is_py25 and f_name in ['generators.py', 'types.py']: continue if thirdparty: