diff --git a/_compatibility.py b/_compatibility.py index 4998b430..8536f4e6 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -4,8 +4,7 @@ python versions. """ import sys -def is_py3k(): - return sys.hexversion >= 0x03000000 +is_py3k = sys.hexversion >= 0x03000000 is_py25 = sys.hexversion < 0x02060000 @@ -63,7 +62,7 @@ except NameError: return s.decode("utf-8") # exec function -if is_py3k(): +if is_py3k: def exec_function(source, global_map): exec(source, global_map) else: @@ -72,7 +71,7 @@ else: # tokenize function import tokenize -if is_py3k(): +if is_py3k: tokenize_func = tokenize.tokenize else: tokenize_func = tokenize.generate_tokens @@ -84,7 +83,7 @@ except ImportError: from io import BytesIO # hasattr function used because python -if is_py3k(): +if is_py3k: hasattr = hasattr else: def hasattr(obj, name): diff --git a/builtin.py b/builtin.py index 50884b2f..520e483c 100644 --- a/builtin.py +++ b/builtin.py @@ -3,7 +3,7 @@ from _compatibility import exec_function, is_py3k import re import sys import os -if is_py3k(): +if is_py3k: import io else: import types @@ -78,7 +78,7 @@ class Parser(CachedModule): # TODO things like dbg: ('not working', 'tuple of integers') } - if is_py3k(): + if is_py3k: map_types['file object'] = 'import io; return io.TextIOWrapper(file)' module_cache = {} @@ -170,14 +170,14 @@ class Parser(CachedModule): try: name = self.name - if name == '__builtin__' and not is_py3k(): + if name == '__builtin__' and not is_py3k: name = 'builtins' f = open(os.path.sep.join(['mixin', name]) + '.py') except IOError: return {} else: mixin_dct = process_code(f.read()) - if is_py3k() and self.name == _Builtin.name: + if is_py3k and self.name == _Builtin.name: # in the case of Py3k xrange is now range mixin_dct['range'] = mixin_dct['xrange'] return mixin_dct @@ -309,7 +309,7 @@ class Parser(CachedModule): # variables for name, value in stmts.items(): - if is_py3k(): + if is_py3k: file_type = io.TextIOWrapper else: file_type = types.FileType @@ -401,7 +401,7 @@ def parse_function_doc(func): class _Builtin(object): """ The builtin scope / module """ # Python 3 compatibility - if is_py3k(): + if is_py3k: name = 'builtins' else: name = '__builtin__' diff --git a/evaluate.py b/evaluate.py index 7f49908d..11fc3ccb 100644 --- a/evaluate.py +++ b/evaluate.py @@ -1168,7 +1168,7 @@ def get_iterator_types(inputs): result += gen.get_index_types() elif isinstance(gen, Instance): # __iter__ returned an instance. - name = '__next__' if is_py3k() else 'next' + name = '__next__' if is_py3k else 'next' try: result += gen.execute_subscope_by_name(name) except KeyError: diff --git a/keywords.py b/keywords.py index 3c52223a..f7dd0817 100644 --- a/keywords.py +++ b/keywords.py @@ -14,7 +14,7 @@ except ImportError: # Python 2.5 pydoc_topics = None -if is_py3k(): +if is_py3k: keys = keyword.kwlist else: keys = keyword.kwlist + ['None', 'False', 'True'] diff --git a/parsing.py b/parsing.py index c7406968..fd9da882 100644 --- a/parsing.py +++ b/parsing.py @@ -1049,7 +1049,7 @@ class PyFuzzyParser(object): self.user_stmt = None self.code = code + '\n' # end with \n, because the parser needs it self.no_docstr = no_docstr - if is_py3k(): + if is_py3k: self.code = self.code.encode() # initialize global Scope