summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-12-31 12:57:11 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-12-31 13:07:02 -0500
commit3d8526412e90f645ecc4b3ae9b567cb2c73fe3aa (patch)
tree32292a12338347b5d8a64b49dcc2d33f4801dd30
parent39f8f3ed43cf82cdf30b57d7f9624addcbd9e372 (diff)
downloadpython-coveragepy-git-3d8526412e90f645ecc4b3ae9b567cb2c73fe3aa.tar.gz
refactor: remove code that was only needed for Python 3.6
-rw-r--r--coverage/env.py12
-rw-r--r--coverage/execfile.py23
-rw-r--r--tests/test_execfile.py1
3 files changed, 8 insertions, 28 deletions
diff --git a/coverage/env.py b/coverage/env.py
index f20b083e..a00cfa07 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -57,18 +57,6 @@ class PYBEHAVIOR:
# Can co_lnotab have negative deltas?
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))
-
- # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It
- # used to be an empty string (meaning the current directory). It changed
- # to be the actual path to the current directory, so that os.chdir wouldn't
- # affect the outcome.
- actual_syspath0_dash_m = (
- (CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3))) or
- (PYPY and (PYPYVERSION >= (7, 3, 4)))
- )
-
# 3.7 changed how functions with only docstrings are numbered.
docstring_only_function = (not PYPY) and ((3, 7, 0, 'beta', 5) <= PYVERSION <= (3, 10))
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 01ddd0cd..b5d3a65f 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -80,10 +80,7 @@ class PyRunner:
This needs to happen before any importing, and without importing anything.
"""
if self.as_module:
- if env.PYBEHAVIOR.actual_syspath0_dash_m:
- path0 = os.getcwd()
- else:
- path0 = ""
+ path0 = os.getcwd()
elif os.path.isdir(self.arg0):
# Running a directory means running the __main__.py file in that
# directory.
@@ -295,18 +292,14 @@ def make_code_from_pyc(filename):
if magic != PYC_MAGIC_NUMBER:
raise NoCode(f"Bad magic number in .pyc file: {magic!r} != {PYC_MAGIC_NUMBER!r}")
- date_based = True
- if env.PYBEHAVIOR.hashed_pyc_pep552:
- flags = struct.unpack('<L', fpyc.read(4))[0]
- hash_based = flags & 0x01
- if hash_based:
- fpyc.read(8) # Skip the hash.
- date_based = False
- if date_based:
+ flags = struct.unpack('<L', fpyc.read(4))[0]
+ hash_based = flags & 0x01
+ if hash_based:
+ fpyc.read(8) # Skip the hash.
+ else:
# Skip the junk in the header that we don't need.
- fpyc.read(4) # Skip the moddate.
- # 3.3 added another long to the header (size), skip it.
- fpyc.read(4)
+ fpyc.read(4) # Skip the moddate.
+ fpyc.read(4) # Skip the size.
# The rest of the file is the code object we want.
code = marshal.load(fpyc)
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index 9c8b9233..6d316700 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -242,7 +242,6 @@ class RunPycFileTest(CoverageTest):
# In some environments, the pycfile persists and pollutes another test.
os.remove(pycfile)
- @pytest.mark.skipif(not env.PYBEHAVIOR.hashed_pyc_pep552, reason="No hashed .pyc here")
def test_running_hashed_pyc(self):
pycfile = self.make_pyc(invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH)
run_python_file([pycfile])