1
0
forked from VimPlug/jedi

Remove is_py3 and is_py35

This commit is contained in:
Dave Halter
2020-07-02 02:22:09 +02:00
parent 17343bb57c
commit 0cd6a8f5cc
5 changed files with 15 additions and 38 deletions

View File

@@ -18,8 +18,6 @@ from zipimport import zipimporter
from jedi.file_io import KnownContentFileIO, ZipFileIO from jedi.file_io import KnownContentFileIO, ZipFileIO
is_py3 = sys.version_info[0] >= 3
is_py35 = is_py3 and sys.version_info[1] >= 5
py_version = int(str(sys.version_info[0]) + str(sys.version_info[1])) py_version = int(str(sys.version_info[0]) + str(sys.version_info[1]))
@@ -105,7 +103,7 @@ def _from_loader(loader, string):
except AttributeError: except AttributeError:
raise ImportError("get_source was not defined on loader") raise ImportError("get_source was not defined on loader")
if is_py3 and f is not importlib.machinery.SourceFileLoader.get_source: if f is not importlib.machinery.SourceFileLoader.get_source:
# Unfortunately we are reading unicode here, not bytes. # Unfortunately we are reading unicode here, not bytes.
# It seems hard to get bytes, because the zip importer # It seems hard to get bytes, because the zip importer
# logic just unpacks the zip file and returns a file descriptor # logic just unpacks the zip file and returns a file descriptor
@@ -143,7 +141,7 @@ class ImplicitNSInfo(object):
self.paths = paths self.paths = paths
if is_py3: if True:
all_suffixes = importlib.machinery.all_suffixes all_suffixes = importlib.machinery.all_suffixes
else: else:
def all_suffixes(): def all_suffixes():

View File

@@ -2,7 +2,7 @@ import os
import time import time
from contextlib import contextmanager from contextlib import contextmanager
from jedi._compatibility import encoding, is_py3, u from jedi._compatibility import u
_inited = False _inited = False
@@ -135,9 +135,4 @@ def print_to_stdout(color, str_out):
""" """
col = getattr(Fore, color) col = getattr(Fore, color)
_lazy_colorama_init() _lazy_colorama_init()
if not is_py3:
str_out = str_out.encode(encoding, 'replace')
print(col + str_out + Fore.RESET) print(col + str_out + Fore.RESET)
# debug_function = print_to_stdout

View File

@@ -114,7 +114,7 @@ import pytest
import jedi import jedi
from jedi import debug from jedi import debug
from jedi._compatibility import unicode, is_py3 from jedi._compatibility import unicode
from jedi.api.classes import Name from jedi.api.classes import Name
from jedi.api.completion import get_user_context from jedi.api.completion import get_user_context
from jedi import parser_utils from jedi import parser_utils
@@ -401,12 +401,8 @@ def collect_dir_tests(base_dir, test_files, check_thirdparty=False):
path = os.path.join(base_dir, f_name) path = os.path.join(base_dir, f_name)
if is_py3: with open(path, encoding='utf-8', newline='') as f:
with open(path, encoding='utf-8', newline='') as f: source = f.read()
source = f.read()
else:
with open(path) as f:
source = unicode(f.read(), 'UTF-8')
for case in collect_file_tests(path, StringIO(source), for case in collect_file_tests(path, StringIO(source),
lines_to_execute): lines_to_execute):

View File

@@ -7,7 +7,7 @@ import warnings
import pytest import pytest
import jedi import jedi
from jedi._compatibility import is_py3, py_version from jedi._compatibility import py_version
from jedi.inference.compiled import mixed from jedi.inference.compiled import mixed
from importlib import import_module from importlib import import_module
@@ -139,9 +139,7 @@ def test_complete_raw_module():
def test_complete_raw_instance(): def test_complete_raw_instance():
import datetime import datetime
dt = datetime.datetime(2013, 1, 1) dt = datetime.datetime(2013, 1, 1)
completions = ['time', 'timetz', 'timetuple'] completions = ['time', 'timetz', 'timetuple', 'timestamp']
if is_py3:
completions += ['timestamp']
_assert_interpreter_complete('(dt - dt).ti', locals(), completions) _assert_interpreter_complete('(dt - dt).ti', locals(), completions)
@@ -349,12 +347,10 @@ def test_keyword_argument():
assert c.name == 'some_keyword_argument=' assert c.name == 'some_keyword_argument='
assert c.complete == 'ord_argument=' assert c.complete == 'ord_argument='
# This needs inspect.signature to work. # Make it impossible for jedi to find the source of the function.
if is_py3: f.__name__ = 'xSOMETHING'
# Make it impossible for jedi to find the source of the function. c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).complete()
f.__name__ = 'xSOMETHING' assert c.name == 'some_keyword_argument='
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).complete()
assert c.name == 'some_keyword_argument='
def test_more_complex_instances(): def test_more_complex_instances():
@@ -403,16 +399,12 @@ def test_dir_magic_method(allow_unsafe_getattr):
raise AttributeError(name) raise AttributeError(name)
def __dir__(self): def __dir__(self):
if is_py3: return ['foo', 'bar'] + object.__dir__(self)
names = object.__dir__(self)
else:
names = dir(object())
return ['foo', 'bar'] + names
itp = jedi.Interpreter("ca.", [{'ca': CompleteAttrs()}]) itp = jedi.Interpreter("ca.", [{'ca': CompleteAttrs()}])
completions = itp.complete() completions = itp.complete()
names = [c.name for c in completions] names = [c.name for c in completions]
assert ('__dir__' in names) == is_py3 assert ('__dir__' in names) is True
assert '__class__' in names assert '__class__' in names
assert 'foo' in names assert 'foo' in names
assert 'bar' in names assert 'bar' in names

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from jedi._compatibility import is_py3
from jedi import parser_utils from jedi import parser_utils
from parso import parse from parso import parse
from parso.python import tree from parso.python import tree
@@ -55,10 +54,7 @@ def test_hex_values_in_docstring():
''' '''
doc = parser_utils.clean_scope_docstring(next(parse(source).iter_funcdefs())) doc = parser_utils.clean_scope_docstring(next(parse(source).iter_funcdefs()))
if is_py3: assert doc == '\xff'
assert doc == '\xff'
else:
assert doc == u'<EFBFBD>'
@pytest.mark.parametrize( @pytest.mark.parametrize(