Skip to content

Ship compiled pytest tests for Python 3.14 and 3.15; pick by interpreter - #419

Merged
rongxin-liu merged 1 commit into
2022/pythonfrom
python-3.15-pyc
Nov 26, 2026
Merged

rongxin-liu merged 1 commit into
2022/pythonfrom
python-3.15-pyc

Conversation

@rongxin-liu

Copy link
Copy Markdown
Contributor

Summary

The seven checks that run students' pytest files against compiled implementations (tests/bank, tests/fuel, tests/plates, tests/twttr, numb3rs, um, working) now work whether the grader runs Python 3.14 or 3.15. Each implementation ships as <name>.cpython-314.pyc and <name>.cpython-315.pyc (from cs50/cs50p-pytest-tests#8), and a small include_pyc helper in each check includes the one matching sys.version_info under the plain <name>.pyc the rest of the check already expects. Nothing else in the checks changes, and the student-facing side is untouched.

Why not just recompile

The checks exec the bytecode after skipping the .pyc header, and bytecode is specific to a Python minor version. A mismatch does not fail gracefully: 3.14 bytecode under 3.15 segfaults the interpreter; 3.15 under 3.14 aborts with a fatal error. A straight swap would therefore have to land in the same instant as cs50/check's Python moves, and moving cs50/check back (which a production trial should be able to do) would require reverting here too. Carrying both builds removes that coupling.

Also removes an unused from distutils.filelist import findall from tests/plates; distutils was removed in Python 3.12 and the import only worked through setuptools' shim.

Verification

Ran all seven checks with check50 4.0.0-dev (the version cs50/check ships) against the CS50P reference solutions, three ways: these checks on Python 3.14.10, these checks on Python 3.15.2, and the unmodified 2022/python checks on 3.14.10. All three produce identical results, check for check (bank 5/5, plates 7/7, twttr 8/8; fuel 8/9, numb3rs 14/15, um 10/11, working 17/19). The few non-passing checks are the same in all three and reflect the reference solutions lagging checks that were tightened later, not Python or this change. Every check that loads a compiled file passes on both versions.

The seven checks that run students' pytest files against compiled
implementations (tests/bank, tests/fuel, tests/plates, tests/twttr, numb3rs,
um, working) shipped one .pyc per implementation, compiled for Python 3.14.
Bytecode is specific to a minor version and the checks exec it after
skipping the header, so a mismatch crashes the interpreter: 3.14 bytecode
under 3.15 segfaults, 3.15 under 3.14 aborts. That tied the checks to the
grader's exact Python and made moving either one an all-at-once event.

Each implementation now ships as <name>.cpython-314.pyc and
<name>.cpython-315.pyc (from cs50/cs50p-pytest-tests), and a small
include_pyc helper in each check includes the one matching
sys.version_info under the plain <name>.pyc the rest of the check expects.
The checks therefore work unchanged whether the grader runs 3.14 or 3.15.

tests/plates also drops an unused `from distutils.filelist import findall`;
distutils was removed in Python 3.12 and the import only worked through
setuptools' shim.

Verified with check50 4.0.0-dev (as cs50/check ships) against the CS50P
reference solutions on both Pythons: results are identical to each other
and to the unmodified checks on 3.14.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant