Tie CPython Source Claims to a Revision
Core idea
For implementation claims, pin a CPython tag or commit, locate the relevant source and compare its behavior with the matching runtime. A source observation is narrower than a language guarantee. Installed Python source can be inspected directly, but a file digest identifies those bytes only; it does not prove that they equal an upstream tag.
import inspect, colorsyssource = inspect.getsource(colorsys.rgb_to_hsv)print(source.lstrip().startswith('def rgb_to_hsv('))print(colorsys.rgb_to_hsv(1, 0, 0))The local Python implementation is inspectable; the red color result is checked independently.
Expected output:
True(0.0, 1.0, 1)Record a digest without assuming upstream identity
import inspect, hashlib, colorsysdata = inspect.getsource(colorsys.rgb_to_hsv).encode('utf-8')digest = hashlib.sha256(data).hexdigest()print(len(digest), digest == hashlib.sha256(data).hexdigest())The SHA-256 digest is reproducible for these exact source bytes; it is not a revision identifier.
Expected output:
64 TrueCommon mistake
If the tagged source cannot be fetched, record the missing upstream comparison rather than asserting it was reviewed. Built-in C functions may not have inspectable Python source.
Practice
Open the CPython v3.13.5 Lib/colorsys.py source at its pinned tag; record the exact location, compare the function to your installed file and run a boundary-color test. Mark the comparison NOT RUN if unavailable.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reading CPython source
Check your understanding of reading cpython source.
What is printed?
import inspectdef f(): return 3print(inspect.isfunction(f))What is printed?
import hashlibprint(len(hashlib.sha256(b'x').hexdigest()))What proves a source claim is tied to an upstream revision?
What if the tagged file is inaccessible?