From ce55ad5567d461cebf7bd73d9662c6ac36696106 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 24 Mar 2019 12:21:10 -0400 Subject: Move some version conditionals to PYBEHAVIOR --- coverage/env.py | 6 ++++++ coverage/execfile.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'coverage') diff --git a/coverage/env.py b/coverage/env.py index d97b193c..27602431 100644 --- a/coverage/env.py +++ b/coverage/env.py @@ -28,6 +28,12 @@ PY3 = PYVERSION >= (3, 0) class PYBEHAVIOR(object): """Flags indicating this Python's behavior.""" + # Do .pyc files have the source file size recorded in them? + size_in_pyc = (PYVERSION >= (3, 3)) + + # Do .pyc files conform to PEP 552? Hash-based pyc's. + hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4)) + # When a break/continue/return statement in a try block jumps to a finally # block, does the finally block do the break/continue/return (pre-3.8), or # does the finally jump back to the break/continue/return (3.8) to do the diff --git a/coverage/execfile.py b/coverage/execfile.py index 4fc6a85f..0e78e5dc 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -290,7 +290,7 @@ def make_code_from_pyc(filename): raise NoCode("Bad magic number in .pyc file") date_based = True - if env.PYVERSION >= (3, 7, 0, 'alpha', 4): + if env.PYBEHAVIOR.hashed_pyc_pep552: flags = struct.unpack('= (3, 3): + if env.PYBEHAVIOR.size_in_pyc: # 3.3 added another long to the header (size), skip it. fpyc.read(4) -- cgit v1.2.1