summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-05-01 19:25:14 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-05-02 07:38:20 -0400
commitc6ba56c68b2a3850f530cc1fdbf9856a90559a1f (patch)
tree4b2fd9dd4139a5d9ed233ca2da8f1c4952103b39
parentd2dad79e0d0611eb519995bd8696f1ada2bcd2cd (diff)
downloadpython-coveragepy-git-c6ba56c68b2a3850f530cc1fdbf9856a90559a1f.tar.gz
refactor: remove a few more version checks
-rw-r--r--coverage/config.py5
-rw-r--r--coverage/env.py11
-rw-r--r--coverage/multiproc.py11
-rw-r--r--coverage/parser.py3
-rw-r--r--coverage/tomlconfig.py4
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/goldtest.py8
-rw-r--r--tests/test_concurrency.py14
-rw-r--r--tests/test_parser.py2
-rw-r--r--tests/test_phystokens.py2
-rw-r--r--tests/test_process.py5
11 files changed, 17 insertions, 50 deletions
diff --git a/coverage/config.py b/coverage/config.py
index 136e2976..231a2ea9 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -37,10 +37,7 @@ class HandyConfigParser(configparser.RawConfigParser):
def read(self, filenames, encoding_unused=None):
"""Read a file name as UTF-8 configuration data."""
- kwargs = {}
- if env.PYVERSION >= (3, 2):
- kwargs['encoding'] = "utf-8"
- return configparser.RawConfigParser.read(self, filenames, **kwargs)
+ return configparser.RawConfigParser.read(self, filenames, encoding="utf-8")
def has_option(self, section, option):
for section_prefix in self.section_prefixes:
diff --git a/coverage/env.py b/coverage/env.py
index ce6d42c5..cc8ca8b7 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -20,13 +20,10 @@ IRONPYTHON = (platform.python_implementation() == "IronPython")
# Python versions. We amend version_info with one more value, a zero if an
# official version, or 1 if built from source beyond an official version.
PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),)
-PY3 = PYVERSION >= (3, 0)
if PYPY:
PYPYVERSION = sys.pypy_version_info
-PYPY3 = PYPY and PY3
-
# Python behavior.
class PYBEHAVIOR:
"""Flags indicating this Python's behavior."""
@@ -36,7 +33,7 @@ class PYBEHAVIOR:
pep626 = CPYTHON and (PYVERSION > (3, 10, 0, 'alpha', 4))
# Is "if __debug__" optimized away?
- if PYPY3:
+ if PYPY:
optimize_if_debug = True
else:
optimize_if_debug = not pep626
@@ -45,7 +42,7 @@ class PYBEHAVIOR:
optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4))
if pep626:
optimize_if_not_debug = False
- if PYPY3:
+ if PYPY:
optimize_if_not_debug = True
# Is "if not __debug__" optimized away even better?
@@ -54,7 +51,7 @@ class PYBEHAVIOR:
optimize_if_not_debug2 = False
# Can co_lnotab have negative deltas?
- negative_lnotab = (PYVERSION >= (3, 6)) and not (PYPY and PYPYVERSION < (7, 2))
+ negative_lnotab = not (PYPY and PYPYVERSION < (7, 2))
# Do .pyc files conform to PEP 552? Hash-based pyc's.
hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4))
@@ -65,7 +62,7 @@ class PYBEHAVIOR:
# affect the outcome.
actual_syspath0_dash_m = (
(CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3))) or
- (PYPY3 and (PYPYVERSION >= (7, 3, 4)))
+ (PYPY and (PYPYVERSION >= (7, 3, 4)))
)
# 3.7 changed how functions with only docstrings are numbered.
diff --git a/coverage/multiproc.py b/coverage/multiproc.py
index 6a104520..4b3c99f7 100644
--- a/coverage/multiproc.py
+++ b/coverage/multiproc.py
@@ -18,11 +18,7 @@ from coverage.misc import contract
PATCHED_MARKER = "_coverage$patched"
-if env.PYVERSION >= (3, 4):
- OriginalProcess = multiprocessing.process.BaseProcess
-else:
- OriginalProcess = multiprocessing.Process
-
+OriginalProcess = multiprocessing.process.BaseProcess
original_bootstrap = OriginalProcess._bootstrap
class ProcessWithCoverage(OriginalProcess): # pylint: disable=abstract-method
@@ -79,10 +75,7 @@ def patch_multiprocessing(rcfile):
if hasattr(multiprocessing, PATCHED_MARKER):
return
- if env.PYVERSION >= (3, 4):
- OriginalProcess._bootstrap = ProcessWithCoverage._bootstrap
- else:
- multiprocessing.Process = ProcessWithCoverage
+ OriginalProcess._bootstrap = ProcessWithCoverage._bootstrap
# Set the value in ProcessWithCoverage that will be pickled into the child
# process.
diff --git a/coverage/parser.py b/coverage/parser.py
index f847d970..445eeeab 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -598,8 +598,7 @@ class AstArcAnalyzer:
_line__ClassDef = _line_decorated
def _line__Dict(self, node):
- # Python 3.5 changed how dict literals are made.
- if env.PYVERSION >= (3, 5) and node.keys:
+ if node.keys:
if node.keys[0] is not None:
return node.keys[0].lineno
else:
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py
index d8055455..8c96fc26 100644
--- a/coverage/tomlconfig.py
+++ b/coverage/tomlconfig.py
@@ -37,9 +37,7 @@ class TomlConfigParser:
# RawConfigParser takes a filename or list of filenames, but we only
# ever call this with a single filename.
assert isinstance(filenames, (bytes, str, os.PathLike))
- filename = filenames
- if env.PYVERSION >= (3, 6):
- filename = os.fspath(filename)
+ filename = os.fspath(filenames)
try:
with open(filename, encoding='utf-8') as fp:
diff --git a/tests/conftest.py b/tests/conftest.py
index a2577086..5e3ed445 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -68,7 +68,7 @@ def set_warnings():
message=r".*find_spec\(\) not found; falling back to find_module\(\)",
)
- if env.PYPY3:
+ if env.PYPY:
# pypy3 warns about unclosed files a lot.
warnings.filterwarnings("ignore", r".*unclosed file", category=ResourceWarning)
diff --git a/tests/goldtest.py b/tests/goldtest.py
index 7ea42754..57e3df66 100644
--- a/tests/goldtest.py
+++ b/tests/goldtest.py
@@ -22,10 +22,6 @@ def gold_path(path):
return os.path.join(TESTS_DIR, "gold", path)
-# "rU" was deprecated in 3.4
-READ_MODE = "rU" if env.PYVERSION < (3, 4) else "r"
-
-
def versioned_directory(d):
"""Find a subdirectory of d specific to the Python version.
For example, on Python 3.6.4 rc 1, it returns the first of these
@@ -80,13 +76,13 @@ def compare(
for f in diff_files:
expected_file = os.path.join(expected_dir, f)
- with open(expected_file, READ_MODE) as fobj:
+ with open(expected_file) as fobj:
expected = fobj.read()
if expected_file.endswith(".xml"):
expected = canonicalize_xml(expected)
actual_file = os.path.join(actual_dir, f)
- with open(actual_file, READ_MODE) as fobj:
+ with open(actual_file) as fobj:
actual = fobj.read()
if actual_file.endswith(".xml"):
actual = canonicalize_xml(actual)
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index a5aed4f1..e1606e83 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -374,12 +374,7 @@ class MultiprocessingTest(CoverageTest):
source = .
""" % concurrency)
- if env.PYVERSION >= (3, 4):
- start_methods = ['fork', 'spawn']
- else:
- start_methods = ['']
-
- for start_method in start_methods:
+ for start_method in ["fork", "spawn"]:
if start_method and start_method not in multiprocessing.get_all_start_methods():
continue
@@ -441,12 +436,7 @@ class MultiprocessingTest(CoverageTest):
omit = */site-packages/*
""")
- if env.PYVERSION >= (3, 4):
- start_methods = ['fork', 'spawn']
- else:
- start_methods = ['']
-
- for start_method in start_methods:
+ for start_method in ["fork", "spawn"]:
if start_method and start_method not in multiprocessing.get_all_start_methods():
continue
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 4a12c59c..46ee25f3 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -138,7 +138,7 @@ class PythonParserTest(CoverageTest):
""")
@pytest.mark.xfail(
- env.PYPY3 and env.PYPYVERSION == (7, 3, 0),
+ env.PYPY and env.PYPYVERSION == (7, 3, 0),
reason="https://bitbucket.org/pypy/pypy/issues/3139",
)
def test_decorator_pragmas(self):
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py
index 06cdd385..82b887e6 100644
--- a/tests/test_phystokens.py
+++ b/tests/test_phystokens.py
@@ -130,7 +130,7 @@ class SourceEncodingTest(CoverageTest):
assert source_encoding(source) == expected, "Wrong encoding in %r" % source
# PyPy3 gets this case wrong. Not sure what I can do about it, so skip the test.
- @pytest.mark.skipif(env.PYPY3, reason="PyPy3 is wrong about non-comment encoding. Skip it.")
+ @pytest.mark.skipif(env.PYPY, reason="PyPy3 is wrong about non-comment encoding. Skip it.")
def test_detect_source_encoding_not_in_comment(self):
# Should not detect anything here
source = b'def parse(src, encoding=None):\n pass'
diff --git a/tests/test_process.py b/tests/test_process.py
index b57a4aa4..18774ef3 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -758,7 +758,7 @@ class ProcessTest(CoverageTest):
# Pypy passes locally, but fails in CI? Perhaps the version of macOS is
# significant? https://foss.heptapod.net/pypy/pypy/-/issues/3074
- @pytest.mark.skipif(env.PYPY3, reason="Pypy is unreliable with this test")
+ @pytest.mark.skipif(env.PYPY, reason="PyPy is unreliable with this test")
# Jython as of 2.7.1rc3 won't compile a filename that isn't utf8.
@pytest.mark.skipif(env.JYTHON, reason="Jython can't handle this test")
def test_lang_c(self):
@@ -871,9 +871,6 @@ class EnvironmentTest(CoverageTest):
actual = self.run_command("coverage run -m process_test.try_execfile")
self.assert_tryexecfile_output(expected, actual)
- @pytest.mark.skipif(env.PYVERSION == (3, 5, 4, 'final', 0, 0),
- reason="3.5.4 broke this: https://bugs.python.org/issue32551"
- )
def test_coverage_run_dir_is_like_python_dir(self):
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())