1
0
forked from VimPlug/jedi

Remove most version_info.major usages

This commit is contained in:
Dave Halter
2020-07-02 03:00:01 +02:00
parent 188fdcd34f
commit 6e184bca97
16 changed files with 26 additions and 95 deletions

View File

@@ -58,15 +58,14 @@ def _create_stub_map(directory_path_info):
def _get_typeshed_directories(version_info):
check_version_list = ['2and3', str(version_info.major)]
check_version_list = ['2and3', '3']
for base in ['stdlib', 'third_party']:
base_path = os.path.join(TYPESHED_PATH, base)
base_list = os.listdir(base_path)
for base_list_entry in base_list:
match = re.match(r'(\d+)\.(\d+)$', base_list_entry)
if match is not None:
if int(match.group(1)) == version_info.major \
and int(match.group(2)) <= version_info.minor:
if int(match.group(1)) == '3' and int(match.group(2)) <= version_info.minor:
check_version_list.append(base_list_entry)
for check_version in check_version_list:

View File

@@ -122,11 +122,7 @@ def get_names_of_node(node):
def is_string(value):
if value.inference_state.environment.version_info.major == 2:
str_classes = (unicode, bytes)
else:
str_classes = (unicode,)
return value.is_compiled() and isinstance(value.get_safe_value(default=None), str_classes)
return value.is_compiled() and isinstance(value.get_safe_value(default=None), str)
def is_literal(value):

View File

@@ -258,9 +258,6 @@ class _BaseTreeInstance(AbstractInstanceValue):
for generator in self.execute_function_slots(iter_slot_names):
if generator.is_instance() and not generator.is_compiled():
# `__next__` logic.
if self.inference_state.environment.version_info.major == 2:
name = u'next'
else:
name = u'__next__'
next_slot_names = generator.get_function_slot_names(name)
if next_slot_names:

View File

@@ -26,9 +26,6 @@ class _ModuleAttributeName(AbstractNameDefinition):
def infer(self):
if self._string_value is not None:
s = self._string_value
if self.parent_context.inference_state.environment.version_info.major == 2 \
and not isinstance(s, bytes):
s = s.encode('utf-8')
return ValueSet([
create_simple_object(self.parent_context.inference_state, s)
])

View File

@@ -182,14 +182,9 @@ def argument_clinic(clinic_string, want_value=False, want_context=False,
@argument_clinic('iterator[, default], /', want_inference_state=True)
def builtins_next(iterators, defaults, inference_state):
if inference_state.environment.version_info.major == 2:
name = 'next'
else:
name = '__next__'
# TODO theoretically we have to check here if something is an iterator.
# That is probably done by checking if it's not a class.
return defaults | iterators.py__getattribute__(name).execute_with_values()
return defaults | iterators.py__getattribute__('__next__').execute_with_values()
@argument_clinic('iterator[, default], /')

View File

@@ -102,9 +102,7 @@ def collect_static_analysis_tests(base_dir, test_files):
@pytest.fixture(scope='session')
def venv_path(tmpdir_factory, environment):
if environment.version_info.major < 3:
pytest.skip("python -m venv does not exist in Python 2")
elif isinstance(environment, InterpreterEnvironment):
if isinstance(environment, InterpreterEnvironment):
# The environment can be a tox virtualenv environment which we don't
# want, so use the system environment.
environment = get_system_environment(

View File

@@ -337,9 +337,7 @@ def test_fuzzy_completion(Script):
def test_math_fuzzy_completion(Script, environment):
script = Script('import math\nmath.og')
expected = ['copysign', 'log', 'log10', 'log1p']
if environment.version_info.major >= 3:
expected.append('log2')
expected = ['copysign', 'log', 'log10', 'log1p', 'log2']
completions = script.complete(fuzzy=True)
assert expected == [comp.name for comp in completions]
for c in completions:

View File

@@ -36,9 +36,6 @@ def test_follow_import_incomplete(Script, environment):
# incomplete `from * import` part
datetime = check_follow_definition_types(Script, "from datetime import datetim")
if environment.version_info.major == 2:
assert datetime == ['class']
else:
assert set(datetime) == {'class', 'instance'} # py3: builtin and pure py version
# os.path check
ospath = check_follow_definition_types(Script, "from os.path import abspat")

View File

@@ -125,7 +125,7 @@ def test_get_signatures_whitespace(Script):
abs(
def x():
pass
""")
""") # noqa
assert_signature(Script, s, 'abs', 0, line=1, column=5)
@@ -239,7 +239,6 @@ def test_complex(Script, environment):
func1, = sig1._name.infer()
func2, = sig2._name.infer()
if environment.version_info.major == 3:
# Do these checks just for Python 3, I'm too lazy to deal with this
# legacy stuff. ~ dave.
assert get_signature(func1.tree_node) \
@@ -373,10 +372,8 @@ def test_keyword_argument_index(Script, environment):
def get(source, column=None):
return Script(source).get_signatures(column=column)[0]
# The signature of sorted changed from 2 to 3.
py2_offset = int(environment.version_info.major == 2)
assert get('sorted([], key=a').index == 1 + py2_offset
assert get('sorted([], key=').index == 1 + py2_offset
assert get('sorted([], key=a').index == 1
assert get('sorted([], key=').index == 1
assert get('sorted([], no_key=a').index is None
kw_func = 'def foo(a, b): pass\nfoo(b=3, a=4)'

View File

@@ -46,9 +46,6 @@ class TestFullNameWithGotoDefinitions(MixinTestFullName, TestCase):
operation = 'infer'
def test_tuple_mapping(self):
if self.environment.version_info.major == 2:
pytest.skip('Python 2 also yields None.')
self.check("""
import re
any_re = re.compile('.*')

View File

@@ -2,8 +2,6 @@
Test of keywords and ``jedi.keywords``
"""
import pytest
def test_goto_keyword(Script):
"""
@@ -17,9 +15,6 @@ def test_goto_keyword(Script):
def test_keyword(Script, environment):
""" github jedi-vim issue #44 """
defs = Script("print").infer()
if environment.version_info.major < 3:
assert defs == []
else:
assert [d.docstring() for d in defs]
assert Script("import").goto() == []
@@ -51,10 +46,6 @@ def test_keyword_attributes(Script):
def test_none_keyword(Script, environment):
if environment.version_info.major == 2:
# Just don't care about Python 2 anymore, it's almost gone.
pytest.skip()
none, = Script('None').complete()
assert not none.docstring()
assert none.name == 'None'

View File

@@ -9,9 +9,6 @@ def test_simple_annotations(Script, environment):
If annotations adhere to PEP-0484, we use them (they override inference),
else they are parsed but ignored
"""
if environment.version_info.major == 2:
pytest.skip()
source = dedent("""\
def annot(a:3):
return a
@@ -45,18 +42,12 @@ def test_simple_annotations(Script, environment):
r'1\n'
])
def test_illegal_forward_references(Script, environment, reference):
if environment.version_info.major == 2:
pytest.skip()
source = 'def foo(bar: "%s"): bar' % reference
assert not Script(source).infer()
def test_lambda_forward_references(Script, environment):
if environment.version_info.major == 2:
pytest.skip()
source = 'def foo(bar: "lambda: 3"): bar'
# For now just receiving the 3 is ok. I'm doubting that this is what we

View File

@@ -16,11 +16,7 @@ def test_simple(inference_state, environment):
upper, = obj.py__getattribute__(u'upper')
objs = list(upper.execute_with_values())
assert len(objs) == 1
if environment.version_info.major == 2:
expected = 'unicode'
else:
expected = 'str'
assert objs[0].name.string_name == expected
assert objs[0].name.string_name == 'str'
def test_builtin_loading(inference_state):
@@ -65,13 +61,9 @@ def test_string_literals(Script, environment):
assert typ('""') == 'str'
assert typ('r""') == 'str'
if environment.version_info.major > 2:
assert typ('br""') == 'bytes'
assert typ('b""') == 'bytes'
assert typ('u""') == 'str'
else:
assert typ('b""') == 'str'
assert typ('u""') == 'unicode'
def test_method_completion(Script, environment):
@@ -94,9 +86,6 @@ def test_time_docstring(Script):
def test_dict_values(Script, environment):
if environment.version_info.major == 2:
# It looks like typeshed for Python 2 returns Any.
pytest.skip()
assert Script('import sys\nsys.modules["alshdb;lasdhf"]').infer()

View File

@@ -103,9 +103,6 @@ def test_sys_getwindowsversion(Script, environment):
# This should only exist on Windows, but type inference should happen
# everywhere.
definitions = Script('import sys; sys.getwindowsversion().major').infer()
if environment.version_info.major == 2:
assert not definitions
else:
def_, = definitions
assert def_.name == 'int'

View File

@@ -10,8 +10,6 @@ import pytest
pytest.param('... == ...', marks=pytest.mark.xfail),
])
def test_equals(Script, environment, source):
if environment.version_info.major < 3:
pytest.skip("Ellipsis does not exists in 2")
script = Script(source)
node = script._module_node.children[0]
first, = script._get_module_context().infer_node(node)

View File

@@ -90,14 +90,8 @@ def test_re_sub(Script, environment):
return {d.name for d in defs}
names = run("import re; re.sub('a', 'a', 'f')")
if environment.version_info.major == 2:
assert names == {'str'}
else:
assert names == {'str'}
# This param is missing because of overloading.
names = run("import re; re.sub('a', 'a')")
if environment.version_info.major == 2:
assert names == {'str', 'unicode'}
else:
assert names == {'str', 'bytes'}