From f4e537fd727b57256210109d2ad486a4fa773c79 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 2 Jul 2020 02:45:35 +0200 Subject: [PATCH] Remove a lot of sys.version_info references --- jedi/inference/compiled/mixed.py | 11 +++++------ .../inference/compiled/subprocess/__init__.py | 11 ++--------- jedi/inference/value/iterable.py | 11 +---------- test/refactor.py | 3 --- test/test_api/test_analysis.py | 8 +------- test/test_api/test_api.py | 6 ++---- test/test_api/test_call_signatures.py | 2 -- test/test_api/test_completion.py | 8 +------- test/test_api/test_environment.py | 1 - test/test_api/test_interpreter.py | 12 ------------ test/test_api/test_project.py | 3 --- test/test_api/test_search.py | 3 --- test/test_inference/test_compiled.py | 2 -- test/test_inference/test_docstring.py | 6 ------ test/test_inference/test_imports.py | 3 +-- test/test_inference/test_mixed.py | 2 -- test/test_inference/test_pyc.py | 19 ++++++++----------- test/test_integration.py | 9 +-------- 18 files changed, 22 insertions(+), 98 deletions(-) diff --git a/jedi/inference/compiled/mixed.py b/jedi/inference/compiled/mixed.py index dec8fc81..e1c452a5 100644 --- a/jedi/inference/compiled/mixed.py +++ b/jedi/inference/compiled/mixed.py @@ -152,12 +152,11 @@ def _load_module(inference_state, path): def _get_object_to_check(python_object): """Check if inspect.getfile has a chance to find the source.""" - if sys.version_info[0] > 2: - try: - python_object = inspect.unwrap(python_object) - except ValueError: - # Can return a ValueError when it wraps around - pass + try: + python_object = inspect.unwrap(python_object) + except ValueError: + # Can return a ValueError when it wraps around + pass if (inspect.ismodule(python_object) or inspect.isclass(python_object) diff --git a/jedi/inference/compiled/subprocess/__init__.py b/jedi/inference/compiled/subprocess/__init__.py index 7dc4a8fa..22f13e79 100644 --- a/jedi/inference/compiled/subprocess/__init__.py +++ b/jedi/inference/compiled/subprocess/__init__.py @@ -334,15 +334,8 @@ class Listener(object): # because stdout is used for IPC. sys.stdout = open(os.devnull, 'w') stdin = sys.stdin - if sys.version_info[0] > 2: - stdout = stdout.buffer - stdin = stdin.buffer - # Python 2 opens streams in text mode on Windows. Set stdout and stdin - # to binary mode. - elif sys.platform == 'win32': - import msvcrt - msvcrt.setmode(stdout.fileno(), os.O_BINARY) - msvcrt.setmode(stdin.fileno(), os.O_BINARY) + stdout = stdout.buffer + stdin = stdin.buffer while True: try: diff --git a/jedi/inference/value/iterable.py b/jedi/inference/value/iterable.py index 6d5521fa..50a689a2 100644 --- a/jedi/inference/value/iterable.py +++ b/jedi/inference/value/iterable.py @@ -2,8 +2,6 @@ Contains all classes and functions to deal with lists, dicts, generators and iterators in general. """ -import sys - from jedi.inference import compiled from jedi.inference import analysis from jedi.inference.lazy_value import LazyKnownValue, LazyKnownValues, \ @@ -31,14 +29,7 @@ class IterableMixin(object): # doing this in the end as well. # This mostly speeds up patterns like `sys.version_info >= (3, 0)` in # typeshed. - if sys.version_info[0] == 2: - # Python 2........... - def get_safe_value(self, default=sentinel): - if default is sentinel: - raise ValueError("There exists no safe value for value %s" % self) - return default - else: - get_safe_value = Value.get_safe_value + get_safe_value = Value.get_safe_value class GeneratorBase(LazyAttributeOverwrite, IterableMixin): diff --git a/test/refactor.py b/test/refactor.py index 2a997b19..1025d95d 100644 --- a/test/refactor.py +++ b/test/refactor.py @@ -8,7 +8,6 @@ from __future__ import with_statement import os import platform import re -import sys from parso import split_lines @@ -90,8 +89,6 @@ def _collect_file_tests(code, path, lines_to_execute): def collect_dir_tests(base_dir, test_files): - if sys.version_info[0] == 2: - return for f_name in os.listdir(base_dir): files_to_execute = [a for a in test_files.items() if a[0] in f_name] lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, []) diff --git a/test/test_api/test_analysis.py b/test/test_api/test_analysis.py index 9723d2eb..64f9c22e 100644 --- a/test/test_api/test_analysis.py +++ b/test/test_api/test_analysis.py @@ -1,10 +1,4 @@ -import sys - -import pytest - - -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") -def test_issue436(Script, skip_python2): +def test_issue436(Script): code = "bar = 0\nbar += 'foo' + 4" errors = set(repr(e) for e in Script(code)._analysis()) assert len(errors) == 2 diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 56516073..c6fc33a7 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -3,7 +3,6 @@ Test all things related to the ``jedi.api`` module. """ import os -import sys from textwrap import dedent import pytest @@ -16,7 +15,6 @@ from jedi.inference.gradual import typeshed from test.helpers import test_dir, get_example_dir -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, EoL") def test_preload_modules(): def check_loaded(*modules): for grammar_cache in cache.parser_cache.values(): @@ -119,8 +117,8 @@ def test_completion_on_complex_literals(Script): # However this has been disabled again, because it apparently annoyed # users. So no completion after j without a space :) assert not Script('4j').complete() - assert ({c.name for c in Script('4j ').complete()} == - {'if', 'and', 'in', 'is', 'not', 'or'}) + assert ({c.name for c in Script('4j ').complete()} + == {'if', 'and', 'in', 'is', 'not', 'or'}) def test_goto_non_name(Script, environment): diff --git a/test/test_api/test_call_signatures.py b/test/test_api/test_call_signatures.py index cbf178a2..5b4e9033 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -1,4 +1,3 @@ -import sys from textwrap import dedent import inspect from unittest import TestCase @@ -515,7 +514,6 @@ def test_signature_index(skip_python2, Script, environment, code, call, expected assert expected_index == index -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 doesn't support __signature__") @pytest.mark.parametrize('code', ['foo', 'instance.foo']) def test_arg_defaults(Script, environment, code): def foo(arg="bla", arg1=1): diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 45716708..5e11b8c4 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -1,6 +1,5 @@ from os.path import join, sep as s, dirname, expanduser import os -import sys from textwrap import dedent import pytest @@ -75,10 +74,7 @@ def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpd dirname = str(tmpdir.mkdir('jedi-test')) filename1 = join(dirname, 'test1.py') filename2 = join(dirname, 'test2.py') - if sys.version_info < (3, 0): - data = "# coding: latin-1\nfoo = 'm\xf6p'\n" - else: - data = "# coding: latin-1\nfoo = 'm\xf6p'\n".encode("latin-1") + data = "# coding: latin-1\nfoo = 'm\xf6p'\n".encode("latin-1") with open(filename1, "wb") as f: f.write(data) @@ -372,7 +368,6 @@ _dict_keys_completion_tests = [ ] -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'added_code, column, expected', _dict_keys_completion_tests ) @@ -398,7 +393,6 @@ def test_dict_keys_completions(Script, added_code, column, expected): assert [c.complete for c in comps] == expected -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_dict_keys_in_weird_case(Script): assert Script('a[\n# foo\nx]').complete(line=2, column=0) diff --git a/test/test_api/test_environment.py b/test/test_api/test_environment.py index 43de23d9..66a34cff 100644 --- a/test/test_api/test_environment.py +++ b/test/test_api/test_environment.py @@ -117,7 +117,6 @@ def test_create_environment_executable(): assert environment.executable == sys.executable -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch): fake_python = os.path.join(str(tmpdir), 'fake_python') with open(fake_python, 'w', newline='') as f: diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index ae149f05..4f2d85d9 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -184,7 +184,6 @@ def test_property_warnings(stacklevel, allow_unsafe_getattr): _assert_interpreter_complete('foo.prop.uppe', locals(), expected) -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize('class_is_findable', [False, True]) def test__getattr__completions(allow_unsafe_getattr, class_is_findable): class CompleteGetattr(object): @@ -275,7 +274,6 @@ def test_property_content(): assert def_.name == 'int' -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_param_completion(): def foo(bar): pass @@ -326,7 +324,6 @@ def test_completion_param_annotations(): assert d.name == 'bytes' -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_keyword_argument(): def f(some_keyword_argument): pass @@ -433,7 +430,6 @@ def test_sys_path_docstring(): # Was an issue in #1298 s.complete(line=2, column=4)[0].docstring() -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'code, completions', [ ('x[0].uppe', ['upper']), @@ -479,7 +475,6 @@ def test_simple_completions(code, completions): assert [d.name for d in defs] == completions -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 doesn't have lru_cache") def test__wrapped__(): from functools import lru_cache @@ -492,7 +487,6 @@ def test__wrapped__(): assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1 -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_illegal_class_instance(): class X: __class__ = 1 @@ -502,14 +496,12 @@ def test_illegal_class_instance(): assert not v.is_instance() -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize('module_name', ['sys', 'time', 'unittest.mock']) def test_core_module_completes(module_name): module = import_module(module_name) assert jedi.Interpreter('module.', [locals()]).complete() -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'code, expected, index', [ ('a(', ['a', 'b', 'c'], 0), @@ -535,7 +527,6 @@ def test_partial_signatures(code, expected, index): assert index == sig.index -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_type_var(): """This was an issue before, see Github #1369""" import typing @@ -544,7 +535,6 @@ def test_type_var(): assert def_.name == 'TypeVar' -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize('class_is_findable', [False, True]) def test_param_annotation_completion(class_is_findable): class Foo: @@ -558,7 +548,6 @@ def test_param_annotation_completion(class_is_findable): assert def_.name == 'bar' -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'code, column, expected', [ ('strs[', 5, ["'asdf'", "'fbar'", "'foo'", Ellipsis]), @@ -589,7 +578,6 @@ def test_dict_completion(code, column, expected): assert [c.complete for c in comps] == expected -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'code, types', [ ('dct[1]', ['int']), diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index 5daa43a3..2eac0ff1 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -1,5 +1,4 @@ import os -import sys import pytest @@ -133,7 +132,6 @@ def test_load_save_project(tmpdir): ('multiprocessin', ['multiprocessing'], dict(complete=True)), ] ) -@pytest.mark.skipif(sys.version_info < (3, 6), reason="Ignore Python 2, because EOL") def test_search(string, full_names, kwargs): some_search_test_var = 1.0 project = Project(test_dir) @@ -152,7 +150,6 @@ def test_search(string, full_names, kwargs): ('test_load_save_p', ['roject'], False), ] ) -@pytest.mark.skipif(sys.version_info < (3, 6), reason="Ignore Python 2, because EOL") def test_complete_search(Script, string, completions, all_scopes): project = Project(test_dir) defs = project.complete_search(string, all_scopes=all_scopes) diff --git a/test/test_api/test_search.py b/test/test_api/test_search.py index a2b333ca..20bb7286 100644 --- a/test/test_api/test_search.py +++ b/test/test_api/test_search.py @@ -66,9 +66,6 @@ class SomeClass: ] ) def test_simple_search(Script, string, descriptions, kwargs): - if sys.version_info < (3, 6): - pytest.skip() - if kwargs.pop('complete', False) is True: defs = Script(path=__file__).complete_search(string, **kwargs) else: diff --git a/test/test_inference/test_compiled.py b/test/test_inference/test_compiled.py index 125d4137..2f7cf90b 100644 --- a/test/test_inference/test_compiled.py +++ b/test/test_inference/test_compiled.py @@ -1,6 +1,5 @@ from textwrap import dedent import math -import sys from collections import Counter from datetime import datetime @@ -146,7 +145,6 @@ def test_parent_context(same_process_inference_state, attribute, expected_name, assert x.parent_context.parent_context is None -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.parametrize( 'obj, expected_names', [ ('', ['str']), diff --git a/test/test_inference/test_docstring.py b/test/test_inference/test_docstring.py index 43a26bbe..3fc54eb1 100644 --- a/test/test_inference/test_docstring.py +++ b/test/test_inference/test_docstring.py @@ -3,7 +3,6 @@ Testing of docstring related issues and especially ``jedi.docstrings``. """ import os -import sys from textwrap import dedent import pytest @@ -25,11 +24,6 @@ except ImportError: else: numpy_unavailable = False -if sys.version_info.major == 2: - # In Python 2 there's an issue with tox/docutils that makes the tests fail, - # Python 2 is soon end-of-life, so just don't support numpydoc for it anymore. - numpydoc_unavailable = True - def test_function_doc(Script): defs = Script(""" diff --git a/test/test_inference/test_imports.py b/test/test_inference/test_imports.py index 60b4fc08..ee216ac7 100644 --- a/test/test_inference/test_imports.py +++ b/test/test_inference/test_imports.py @@ -19,8 +19,7 @@ from ..helpers import get_example_dir, test_dir, test_dir_project, root_dir THIS_DIR = os.path.dirname(__file__) -@pytest.mark.skipif('sys.version_info < (3,3)') -def test_find_module_py33(): +def test_find_module_basic(): """Needs to work like the old find_module.""" assert find_module_py33('_io') == (None, False) with pytest.raises(ImportError): diff --git a/test/test_inference/test_mixed.py b/test/test_inference/test_mixed.py index f04d0340..b4e6c65d 100644 --- a/test/test_inference/test_mixed.py +++ b/test/test_inference/test_mixed.py @@ -1,5 +1,4 @@ from typing import Generic, TypeVar, List -import sys import pytest @@ -86,7 +85,6 @@ def test_mixed_module_cache(): assert isinstance(jedi_module, ModuleValue) -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, EoL") def test_signature(): """ For performance reasons we use the signature of the compiled object and not diff --git a/test/test_inference/test_pyc.py b/test/test_inference/test_pyc.py index fec4c958..f5ef8b29 100644 --- a/test/test_inference/test_pyc.py +++ b/test/test_inference/test_pyc.py @@ -39,16 +39,14 @@ def pyc_project_path(tmpdir): compileall.compile_file(dummy_path) os.remove(dummy_path) - if sys.version_info.major == 3: - # Python3 specific: - # To import pyc modules, we must move them out of the __pycache__ - # directory and rename them to remove ".cpython-%s%d" - # see: http://stackoverflow.com/questions/11648440/python-does-not-detect-pyc-files - pycache = os.path.join(dummy_package_path, "__pycache__") - for f in os.listdir(pycache): - dst = f.replace('.cpython-%s%s' % sys.version_info[:2], "") - dst = os.path.join(dummy_package_path, dst) - shutil.copy(os.path.join(pycache, f), dst) + # To import pyc modules, we must move them out of the __pycache__ + # directory and rename them to remove ".cpython-%s%d" + # see: http://stackoverflow.com/questions/11648440/python-does-not-detect-pyc-files + pycache = os.path.join(dummy_package_path, "__pycache__") + for f in os.listdir(pycache): + dst = f.replace('.cpython-%s%s' % sys.version_info[:2], "") + dst = os.path.join(dummy_package_path, dst) + shutil.copy(os.path.join(pycache, f), dst) try: yield path finally: @@ -56,7 +54,6 @@ def pyc_project_path(tmpdir): @pytest.mark.parametrize('load_unsafe_extensions', [False, True]) -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") def test_pyc(pyc_project_path, environment, load_unsafe_extensions): """ The list of completion must be greater than 2. diff --git a/test/test_integration.py b/test/test_integration.py index 7fa7bc35..2e5703aa 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -1,5 +1,4 @@ import os -import sys import pytest @@ -41,10 +40,7 @@ def test_completion(case, monkeypatch, environment, has_django): if skip_reason is not None: pytest.skip(skip_reason) - if 'pep0484_typing' in case.path and sys.version_info[0] == 2: - pytest.skip('ditch python 2 finally') - - if (not has_django or environment.version_info.major == 2) and case.path.endswith('django.py'): + if (not has_django) and case.path.endswith('django.py'): pytest.skip('Needs django to be installed to run this test.') repo_root = helpers.root_dir monkeypatch.chdir(os.path.join(repo_root, 'jedi')) @@ -65,9 +61,6 @@ def test_refactor(refactor_case, environment): :type refactor_case: :class:`.refactor.RefactoringCase` """ - if sys.version_info < (3, 6): - pytest.skip() - desired_result = refactor_case.get_desired_result() if refactor_case.type == 'error': with pytest.raises(RefactoringError) as e: