diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-01 19:25:14 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-02 07:38:20 -0400 |
commit | c6ba56c68b2a3850f530cc1fdbf9856a90559a1f (patch) | |
tree | 4b2fd9dd4139a5d9ed233ca2da8f1c4952103b39 /coverage | |
parent | d2dad79e0d0611eb519995bd8696f1ada2bcd2cd (diff) | |
download | python-coveragepy-git-c6ba56c68b2a3850f530cc1fdbf9856a90559a1f.tar.gz |
refactor: remove a few more version checks
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/config.py | 5 | ||||
-rw-r--r-- | coverage/env.py | 11 | ||||
-rw-r--r-- | coverage/multiproc.py | 11 | ||||
-rw-r--r-- | coverage/parser.py | 3 | ||||
-rw-r--r-- | coverage/tomlconfig.py | 4 |
5 files changed, 9 insertions, 25 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: |