diff --git a/_compatibility.py b/_compatibility.py index d06f7674..4998b430 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -2,9 +2,12 @@ This is a compatibility module, to make it possible to use jedi also with older python versions. """ +import sys + def is_py3k(): return sys.hexversion >= 0x03000000 -import sys + +is_py25 = sys.hexversion < 0x02060000 # next was defined in python 2.6, in python 3 obj.next won't be possible # anymore diff --git a/keywords.py b/keywords.py index 3a54d721..3c52223a 100644 --- a/keywords.py +++ b/keywords.py @@ -7,8 +7,12 @@ import pydoc try: from pydoc_data import topics as pydoc_topics except ImportError: - # Python 2.5/2.6 - import pydoc_topics + # Python 2.6 + try: + import pydoc_topics + except ImportError: + # Python 2.5 + pydoc_topics = None if is_py3k(): keys = keyword.kwlist @@ -63,4 +67,4 @@ def imitate_pydoc(string): except TypeError: return '' - return pydoc_topics.topics[label] + return pydoc_topics.topics[label] if pydoc_topics else '' diff --git a/test/regression.py b/test/regression.py index 7a81b83f..f2cd792b 100755 --- a/test/regression.py +++ b/test/regression.py @@ -6,6 +6,7 @@ import unittest os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/..') sys.path.append('.') +from _compatibility import is_py25 import functions #functions.set_debug_function(functions.debug.print_to_stdout) @@ -56,7 +57,8 @@ class TestRegression(unittest.TestCase): def test_keyword_doc(self): r = list(self.get_def("or", (1,1))) assert len(r) == 1 - assert len(r[0].doc) > 100 + if not is_py25: + assert len(r[0].doc) > 100 r = list(self.get_def("asfdasfd", (1,1))) assert len(r) == 0 @@ -64,7 +66,8 @@ class TestRegression(unittest.TestCase): def test_operator_doc(self): r = list(self.get_def("a == b", (1,3))) assert len(r) == 1 - assert len(r[0].doc) > 100 + 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()