1
0
forked from VimPlug/jedi

is_py3k() -> is_py3k

This commit is contained in:
David Halter
2012-09-06 02:38:57 +02:00
parent 0008e2c703
commit 18686c1d63
5 changed files with 13 additions and 14 deletions

View File

@@ -4,8 +4,7 @@ python versions.
""" """
import sys import sys
def is_py3k(): is_py3k = sys.hexversion >= 0x03000000
return sys.hexversion >= 0x03000000
is_py25 = sys.hexversion < 0x02060000 is_py25 = sys.hexversion < 0x02060000
@@ -63,7 +62,7 @@ except NameError:
return s.decode("utf-8") return s.decode("utf-8")
# exec function # exec function
if is_py3k(): if is_py3k:
def exec_function(source, global_map): def exec_function(source, global_map):
exec(source, global_map) exec(source, global_map)
else: else:
@@ -72,7 +71,7 @@ else:
# tokenize function # tokenize function
import tokenize import tokenize
if is_py3k(): if is_py3k:
tokenize_func = tokenize.tokenize tokenize_func = tokenize.tokenize
else: else:
tokenize_func = tokenize.generate_tokens tokenize_func = tokenize.generate_tokens
@@ -84,7 +83,7 @@ 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:
def hasattr(obj, name): def hasattr(obj, name):

View File

@@ -3,7 +3,7 @@ from _compatibility import exec_function, is_py3k
import re import re
import sys import sys
import os import os
if is_py3k(): if is_py3k:
import io import io
else: else:
import types import types
@@ -78,7 +78,7 @@ class Parser(CachedModule):
# TODO things like dbg: ('not working', 'tuple of integers') # 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)' map_types['file object'] = 'import io; return io.TextIOWrapper(file)'
module_cache = {} module_cache = {}
@@ -170,14 +170,14 @@ class Parser(CachedModule):
try: try:
name = self.name name = self.name
if name == '__builtin__' and not is_py3k(): if name == '__builtin__' and not is_py3k:
name = 'builtins' name = 'builtins'
f = open(os.path.sep.join(['mixin', name]) + '.py') f = open(os.path.sep.join(['mixin', name]) + '.py')
except IOError: except IOError:
return {} return {}
else: else:
mixin_dct = process_code(f.read()) 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 # in the case of Py3k xrange is now range
mixin_dct['range'] = mixin_dct['xrange'] mixin_dct['range'] = mixin_dct['xrange']
return mixin_dct return mixin_dct
@@ -309,7 +309,7 @@ class Parser(CachedModule):
# variables # variables
for name, value in stmts.items(): for name, value in stmts.items():
if is_py3k(): if is_py3k:
file_type = io.TextIOWrapper file_type = io.TextIOWrapper
else: else:
file_type = types.FileType file_type = types.FileType
@@ -401,7 +401,7 @@ def parse_function_doc(func):
class _Builtin(object): class _Builtin(object):
""" The builtin scope / module """ """ The builtin scope / module """
# Python 3 compatibility # Python 3 compatibility
if is_py3k(): if is_py3k:
name = 'builtins' name = 'builtins'
else: else:
name = '__builtin__' name = '__builtin__'

View File

@@ -1168,7 +1168,7 @@ def get_iterator_types(inputs):
result += gen.get_index_types() result += gen.get_index_types()
elif isinstance(gen, Instance): elif isinstance(gen, Instance):
# __iter__ returned an instance. # __iter__ returned an instance.
name = '__next__' if is_py3k() else 'next' name = '__next__' if is_py3k else 'next'
try: try:
result += gen.execute_subscope_by_name(name) result += gen.execute_subscope_by_name(name)
except KeyError: except KeyError:

View File

@@ -14,7 +14,7 @@ except ImportError:
# Python 2.5 # Python 2.5
pydoc_topics = None pydoc_topics = None
if is_py3k(): if is_py3k:
keys = keyword.kwlist keys = keyword.kwlist
else: else:
keys = keyword.kwlist + ['None', 'False', 'True'] keys = keyword.kwlist + ['None', 'False', 'True']

View File

@@ -1049,7 +1049,7 @@ class PyFuzzyParser(object):
self.user_stmt = None self.user_stmt = None
self.code = code + '\n' # end with \n, because the parser needs it self.code = code + '\n' # end with \n, because the parser needs it
self.no_docstr = no_docstr self.no_docstr = no_docstr
if is_py3k(): if is_py3k:
self.code = self.code.encode() self.code = self.code.encode()
# initialize global Scope # initialize global Scope