mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Remove most version_info.major usages
This commit is contained in:
@@ -58,15 +58,14 @@ def _create_stub_map(directory_path_info):
|
|||||||
|
|
||||||
|
|
||||||
def _get_typeshed_directories(version_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']:
|
for base in ['stdlib', 'third_party']:
|
||||||
base_path = os.path.join(TYPESHED_PATH, base)
|
base_path = os.path.join(TYPESHED_PATH, base)
|
||||||
base_list = os.listdir(base_path)
|
base_list = os.listdir(base_path)
|
||||||
for base_list_entry in base_list:
|
for base_list_entry in base_list:
|
||||||
match = re.match(r'(\d+)\.(\d+)$', base_list_entry)
|
match = re.match(r'(\d+)\.(\d+)$', base_list_entry)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
if int(match.group(1)) == version_info.major \
|
if int(match.group(1)) == '3' and int(match.group(2)) <= version_info.minor:
|
||||||
and int(match.group(2)) <= version_info.minor:
|
|
||||||
check_version_list.append(base_list_entry)
|
check_version_list.append(base_list_entry)
|
||||||
|
|
||||||
for check_version in check_version_list:
|
for check_version in check_version_list:
|
||||||
|
|||||||
@@ -122,11 +122,7 @@ def get_names_of_node(node):
|
|||||||
|
|
||||||
|
|
||||||
def is_string(value):
|
def is_string(value):
|
||||||
if value.inference_state.environment.version_info.major == 2:
|
return value.is_compiled() and isinstance(value.get_safe_value(default=None), str)
|
||||||
str_classes = (unicode, bytes)
|
|
||||||
else:
|
|
||||||
str_classes = (unicode,)
|
|
||||||
return value.is_compiled() and isinstance(value.get_safe_value(default=None), str_classes)
|
|
||||||
|
|
||||||
|
|
||||||
def is_literal(value):
|
def is_literal(value):
|
||||||
|
|||||||
@@ -258,10 +258,7 @@ class _BaseTreeInstance(AbstractInstanceValue):
|
|||||||
for generator in self.execute_function_slots(iter_slot_names):
|
for generator in self.execute_function_slots(iter_slot_names):
|
||||||
if generator.is_instance() and not generator.is_compiled():
|
if generator.is_instance() and not generator.is_compiled():
|
||||||
# `__next__` logic.
|
# `__next__` logic.
|
||||||
if self.inference_state.environment.version_info.major == 2:
|
name = u'__next__'
|
||||||
name = u'next'
|
|
||||||
else:
|
|
||||||
name = u'__next__'
|
|
||||||
next_slot_names = generator.get_function_slot_names(name)
|
next_slot_names = generator.get_function_slot_names(name)
|
||||||
if next_slot_names:
|
if next_slot_names:
|
||||||
yield LazyKnownValues(
|
yield LazyKnownValues(
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
|||||||
def infer(self):
|
def infer(self):
|
||||||
if self._string_value is not None:
|
if self._string_value is not None:
|
||||||
s = self._string_value
|
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([
|
return ValueSet([
|
||||||
create_simple_object(self.parent_context.inference_state, s)
|
create_simple_object(self.parent_context.inference_state, s)
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -182,14 +182,9 @@ def argument_clinic(clinic_string, want_value=False, want_context=False,
|
|||||||
|
|
||||||
@argument_clinic('iterator[, default], /', want_inference_state=True)
|
@argument_clinic('iterator[, default], /', want_inference_state=True)
|
||||||
def builtins_next(iterators, defaults, inference_state):
|
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.
|
# TODO theoretically we have to check here if something is an iterator.
|
||||||
# That is probably done by checking if it's not a class.
|
# 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], /')
|
@argument_clinic('iterator[, default], /')
|
||||||
|
|||||||
@@ -102,9 +102,7 @@ def collect_static_analysis_tests(base_dir, test_files):
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def venv_path(tmpdir_factory, environment):
|
def venv_path(tmpdir_factory, environment):
|
||||||
if environment.version_info.major < 3:
|
if isinstance(environment, InterpreterEnvironment):
|
||||||
pytest.skip("python -m venv does not exist in Python 2")
|
|
||||||
elif isinstance(environment, InterpreterEnvironment):
|
|
||||||
# The environment can be a tox virtualenv environment which we don't
|
# The environment can be a tox virtualenv environment which we don't
|
||||||
# want, so use the system environment.
|
# want, so use the system environment.
|
||||||
environment = get_system_environment(
|
environment = get_system_environment(
|
||||||
|
|||||||
@@ -337,9 +337,7 @@ def test_fuzzy_completion(Script):
|
|||||||
|
|
||||||
def test_math_fuzzy_completion(Script, environment):
|
def test_math_fuzzy_completion(Script, environment):
|
||||||
script = Script('import math\nmath.og')
|
script = Script('import math\nmath.og')
|
||||||
expected = ['copysign', 'log', 'log10', 'log1p']
|
expected = ['copysign', 'log', 'log10', 'log1p', 'log2']
|
||||||
if environment.version_info.major >= 3:
|
|
||||||
expected.append('log2')
|
|
||||||
completions = script.complete(fuzzy=True)
|
completions = script.complete(fuzzy=True)
|
||||||
assert expected == [comp.name for comp in completions]
|
assert expected == [comp.name for comp in completions]
|
||||||
for c in completions:
|
for c in completions:
|
||||||
|
|||||||
@@ -36,10 +36,7 @@ def test_follow_import_incomplete(Script, environment):
|
|||||||
|
|
||||||
# incomplete `from * import` part
|
# incomplete `from * import` part
|
||||||
datetime = check_follow_definition_types(Script, "from datetime import datetim")
|
datetime = check_follow_definition_types(Script, "from datetime import datetim")
|
||||||
if environment.version_info.major == 2:
|
assert set(datetime) == {'class', 'instance'} # py3: builtin and pure py version
|
||||||
assert datetime == ['class']
|
|
||||||
else:
|
|
||||||
assert set(datetime) == {'class', 'instance'} # py3: builtin and pure py version
|
|
||||||
# os.path check
|
# os.path check
|
||||||
ospath = check_follow_definition_types(Script, "from os.path import abspat")
|
ospath = check_follow_definition_types(Script, "from os.path import abspat")
|
||||||
assert set(ospath) == {'function'}
|
assert set(ospath) == {'function'}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ def test_get_signatures_whitespace(Script):
|
|||||||
abs(
|
abs(
|
||||||
def x():
|
def x():
|
||||||
pass
|
pass
|
||||||
""")
|
""") # noqa
|
||||||
assert_signature(Script, s, 'abs', 0, line=1, column=5)
|
assert_signature(Script, s, 'abs', 0, line=1, column=5)
|
||||||
|
|
||||||
|
|
||||||
@@ -239,13 +239,12 @@ def test_complex(Script, environment):
|
|||||||
func1, = sig1._name.infer()
|
func1, = sig1._name.infer()
|
||||||
func2, = sig2._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
|
||||||
# Do these checks just for Python 3, I'm too lazy to deal with this
|
# legacy stuff. ~ dave.
|
||||||
# legacy stuff. ~ dave.
|
assert get_signature(func1.tree_node) \
|
||||||
assert get_signature(func1.tree_node) \
|
== 'compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]'
|
||||||
== 'compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]'
|
assert get_signature(func2.tree_node) \
|
||||||
assert get_signature(func2.tree_node) \
|
== 'compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) ->\nPattern[AnyStr]'
|
||||||
== 'compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) ->\nPattern[AnyStr]'
|
|
||||||
|
|
||||||
# jedi-vim #70
|
# jedi-vim #70
|
||||||
s = """def foo("""
|
s = """def foo("""
|
||||||
@@ -373,10 +372,8 @@ def test_keyword_argument_index(Script, environment):
|
|||||||
def get(source, column=None):
|
def get(source, column=None):
|
||||||
return Script(source).get_signatures(column=column)[0]
|
return Script(source).get_signatures(column=column)[0]
|
||||||
|
|
||||||
# The signature of sorted changed from 2 to 3.
|
assert get('sorted([], key=a').index == 1
|
||||||
py2_offset = int(environment.version_info.major == 2)
|
assert get('sorted([], key=').index == 1
|
||||||
assert get('sorted([], key=a').index == 1 + py2_offset
|
|
||||||
assert get('sorted([], key=').index == 1 + py2_offset
|
|
||||||
assert get('sorted([], no_key=a').index is None
|
assert get('sorted([], no_key=a').index is None
|
||||||
|
|
||||||
kw_func = 'def foo(a, b): pass\nfoo(b=3, a=4)'
|
kw_func = 'def foo(a, b): pass\nfoo(b=3, a=4)'
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ class TestFullNameWithGotoDefinitions(MixinTestFullName, TestCase):
|
|||||||
operation = 'infer'
|
operation = 'infer'
|
||||||
|
|
||||||
def test_tuple_mapping(self):
|
def test_tuple_mapping(self):
|
||||||
if self.environment.version_info.major == 2:
|
|
||||||
pytest.skip('Python 2 also yields None.')
|
|
||||||
|
|
||||||
self.check("""
|
self.check("""
|
||||||
import re
|
import re
|
||||||
any_re = re.compile('.*')
|
any_re = re.compile('.*')
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
Test of keywords and ``jedi.keywords``
|
Test of keywords and ``jedi.keywords``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_goto_keyword(Script):
|
def test_goto_keyword(Script):
|
||||||
"""
|
"""
|
||||||
@@ -17,10 +15,7 @@ def test_goto_keyword(Script):
|
|||||||
def test_keyword(Script, environment):
|
def test_keyword(Script, environment):
|
||||||
""" github jedi-vim issue #44 """
|
""" github jedi-vim issue #44 """
|
||||||
defs = Script("print").infer()
|
defs = Script("print").infer()
|
||||||
if environment.version_info.major < 3:
|
assert [d.docstring() for d in defs]
|
||||||
assert defs == []
|
|
||||||
else:
|
|
||||||
assert [d.docstring() for d in defs]
|
|
||||||
|
|
||||||
assert Script("import").goto() == []
|
assert Script("import").goto() == []
|
||||||
|
|
||||||
@@ -51,10 +46,6 @@ def test_keyword_attributes(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_none_keyword(Script, environment):
|
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()
|
none, = Script('None').complete()
|
||||||
assert not none.docstring()
|
assert not none.docstring()
|
||||||
assert none.name == 'None'
|
assert none.name == 'None'
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ def test_simple_annotations(Script, environment):
|
|||||||
If annotations adhere to PEP-0484, we use them (they override inference),
|
If annotations adhere to PEP-0484, we use them (they override inference),
|
||||||
else they are parsed but ignored
|
else they are parsed but ignored
|
||||||
"""
|
"""
|
||||||
if environment.version_info.major == 2:
|
|
||||||
pytest.skip()
|
|
||||||
|
|
||||||
source = dedent("""\
|
source = dedent("""\
|
||||||
def annot(a:3):
|
def annot(a:3):
|
||||||
return a
|
return a
|
||||||
@@ -45,18 +42,12 @@ def test_simple_annotations(Script, environment):
|
|||||||
r'1\n'
|
r'1\n'
|
||||||
])
|
])
|
||||||
def test_illegal_forward_references(Script, environment, reference):
|
def test_illegal_forward_references(Script, environment, reference):
|
||||||
if environment.version_info.major == 2:
|
|
||||||
pytest.skip()
|
|
||||||
|
|
||||||
source = 'def foo(bar: "%s"): bar' % reference
|
source = 'def foo(bar: "%s"): bar' % reference
|
||||||
|
|
||||||
assert not Script(source).infer()
|
assert not Script(source).infer()
|
||||||
|
|
||||||
|
|
||||||
def test_lambda_forward_references(Script, environment):
|
def test_lambda_forward_references(Script, environment):
|
||||||
if environment.version_info.major == 2:
|
|
||||||
pytest.skip()
|
|
||||||
|
|
||||||
source = 'def foo(bar: "lambda: 3"): bar'
|
source = 'def foo(bar: "lambda: 3"): bar'
|
||||||
|
|
||||||
# For now just receiving the 3 is ok. I'm doubting that this is what we
|
# For now just receiving the 3 is ok. I'm doubting that this is what we
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ def test_simple(inference_state, environment):
|
|||||||
upper, = obj.py__getattribute__(u'upper')
|
upper, = obj.py__getattribute__(u'upper')
|
||||||
objs = list(upper.execute_with_values())
|
objs = list(upper.execute_with_values())
|
||||||
assert len(objs) == 1
|
assert len(objs) == 1
|
||||||
if environment.version_info.major == 2:
|
assert objs[0].name.string_name == 'str'
|
||||||
expected = 'unicode'
|
|
||||||
else:
|
|
||||||
expected = 'str'
|
|
||||||
assert objs[0].name.string_name == expected
|
|
||||||
|
|
||||||
|
|
||||||
def test_builtin_loading(inference_state):
|
def test_builtin_loading(inference_state):
|
||||||
@@ -65,13 +61,9 @@ def test_string_literals(Script, environment):
|
|||||||
|
|
||||||
assert typ('""') == 'str'
|
assert typ('""') == 'str'
|
||||||
assert typ('r""') == 'str'
|
assert typ('r""') == 'str'
|
||||||
if environment.version_info.major > 2:
|
assert typ('br""') == 'bytes'
|
||||||
assert typ('br""') == 'bytes'
|
assert typ('b""') == 'bytes'
|
||||||
assert typ('b""') == 'bytes'
|
assert typ('u""') == 'str'
|
||||||
assert typ('u""') == 'str'
|
|
||||||
else:
|
|
||||||
assert typ('b""') == 'str'
|
|
||||||
assert typ('u""') == 'unicode'
|
|
||||||
|
|
||||||
|
|
||||||
def test_method_completion(Script, environment):
|
def test_method_completion(Script, environment):
|
||||||
@@ -94,9 +86,6 @@ def test_time_docstring(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_dict_values(Script, environment):
|
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()
|
assert Script('import sys\nsys.modules["alshdb;lasdhf"]').infer()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,8 @@ def test_sys_getwindowsversion(Script, environment):
|
|||||||
# This should only exist on Windows, but type inference should happen
|
# This should only exist on Windows, but type inference should happen
|
||||||
# everywhere.
|
# everywhere.
|
||||||
definitions = Script('import sys; sys.getwindowsversion().major').infer()
|
definitions = Script('import sys; sys.getwindowsversion().major').infer()
|
||||||
if environment.version_info.major == 2:
|
def_, = definitions
|
||||||
assert not definitions
|
assert def_.name == 'int'
|
||||||
else:
|
|
||||||
def_, = definitions
|
|
||||||
assert def_.name == 'int'
|
|
||||||
|
|
||||||
|
|
||||||
def test_sys_hexversion(Script):
|
def test_sys_hexversion(Script):
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import pytest
|
|||||||
pytest.param('... == ...', marks=pytest.mark.xfail),
|
pytest.param('... == ...', marks=pytest.mark.xfail),
|
||||||
])
|
])
|
||||||
def test_equals(Script, environment, source):
|
def test_equals(Script, environment, source):
|
||||||
if environment.version_info.major < 3:
|
|
||||||
pytest.skip("Ellipsis does not exists in 2")
|
|
||||||
script = Script(source)
|
script = Script(source)
|
||||||
node = script._module_node.children[0]
|
node = script._module_node.children[0]
|
||||||
first, = script._get_module_context().infer_node(node)
|
first, = script._get_module_context().infer_node(node)
|
||||||
|
|||||||
@@ -90,14 +90,8 @@ def test_re_sub(Script, environment):
|
|||||||
return {d.name for d in defs}
|
return {d.name for d in defs}
|
||||||
|
|
||||||
names = run("import re; re.sub('a', 'a', 'f')")
|
names = run("import re; re.sub('a', 'a', 'f')")
|
||||||
if environment.version_info.major == 2:
|
assert names == {'str'}
|
||||||
assert names == {'str'}
|
|
||||||
else:
|
|
||||||
assert names == {'str'}
|
|
||||||
|
|
||||||
# This param is missing because of overloading.
|
# This param is missing because of overloading.
|
||||||
names = run("import re; re.sub('a', 'a')")
|
names = run("import re; re.sub('a', 'a')")
|
||||||
if environment.version_info.major == 2:
|
assert names == {'str', 'bytes'}
|
||||||
assert names == {'str', 'unicode'}
|
|
||||||
else:
|
|
||||||
assert names == {'str', 'bytes'}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user