Skip to content

Commit b72ad0f

Browse files
committed
Remove has_flags conditions from src._pytest.assertion.rewrite._read_pyc
1 parent 77042f7 commit b72ad0f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,31 +375,29 @@ def _read_pyc(
375375
except OSError:
376376
return None
377377
with fp:
378-
# https://www.python.org/dev/peps/pep-0552/
379-
has_flags = sys.version_info >= (3, 7)
380378
try:
381379
stat_result = os.stat(source)
382380
mtime = int(stat_result.st_mtime)
383381
size = stat_result.st_size
384-
data = fp.read(16 if has_flags else 12)
382+
data = fp.read(16)
385383
except OSError as e:
386384
trace(f"_read_pyc({source}): OSError {e}")
387385
return None
388386
# Check for invalid or out of date pyc file.
389-
if len(data) != (16 if has_flags else 12):
387+
if len(data) != (16):
390388
trace("_read_pyc(%s): invalid pyc (too short)" % source)
391389
return None
392390
if data[:4] != importlib.util.MAGIC_NUMBER:
393391
trace("_read_pyc(%s): invalid pyc (bad magic number)" % source)
394392
return None
395-
if has_flags and data[4:8] != b"\x00\x00\x00\x00":
393+
if data[4:8] != b"\x00\x00\x00\x00":
396394
trace("_read_pyc(%s): invalid pyc (unsupported flags)" % source)
397395
return None
398-
mtime_data = data[8 if has_flags else 4 : 12 if has_flags else 8]
396+
mtime_data = data[8:12]
399397
if int.from_bytes(mtime_data, "little") != mtime & 0xFFFFFFFF:
400398
trace("_read_pyc(%s): out of date" % source)
401399
return None
402-
size_data = data[12 if has_flags else 8 : 16 if has_flags else 12]
400+
size_data = data[12:16]
403401
if int.from_bytes(size_data, "little") != size & 0xFFFFFFFF:
404402
trace("_read_pyc(%s): invalid pyc (incorrect size)" % source)
405403
return None

0 commit comments

Comments
 (0)