-
Notifications
You must be signed in to change notification settings - Fork 0
The small int cache is -5 to 1024 in 3.15, not -5 to 256 #33
Copy link
Copy link
Open
Labels
area/objectsThe object model, types, slots and the builtin typesThe object model, types, slots and the builtin typeskind/researchInvestigation that produces a written answer rather than an implementationInvestigation that produces a written answer rather than an implementationpriority/p0Blocks the current milestoneBlocks the current milestonestatus/needs-decisionWaiting on a decision, with the measurement that would make it namedWaiting on a decision, with the measurement that would make it named
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
area/objectsThe object model, types, slots and the builtin typesThe object model, types, slots and the builtin typeskind/researchInvestigation that produces a written answer rather than an implementationInvestigation that produces a written answer rather than an implementationpriority/p0Blocks the current milestoneBlocks the current milestonestatus/needs-decisionWaiting on a decision, with the measurement that would make it namedWaiting on a decision, with the measurement that would make it named
The most repeated example in every Python tutorial is wrong for the version this project is pinned to.
CPython 3.15 widens the small integer cache from 257 values to 1030.
_PY_NSMALLPOSINTSis 1025 and_PY_NSMALLNEGINTSis 5, atInclude/internal/pycore_runtime_structs.h:97-98@v3.15.0rc1#_PY_NSMALLPOSINTS, so the cached range is -5 through 1024 inclusive rather than -5 through 256.Verified, not assumed
Same probe, two interpreters, constructing each integer twice through
int(str(n))so the compiler cannot fold them into one constant.On 3.15.0rc1,
int(str(257)) is int(str(257))isTrue. On 3.14.7 it isFalse.Why this matters more than one wrong example
It is the whole argument for this project in one line. Every CPython explainer that teaches
256 is 257was correct when it was written and nothing told the author when it stopped being correct. That is the failure mode the citation checker exists to catch, and this is a live instance of it found on day one.T08 needs redesigning. The lesson's prediction gate is built on
256 is 256being True and257 is 257being False. On the pin, both are True. The gate still works but the boundary moves to 1024, and the more interesting question becomes why there is a boundary at all rather than where it sits.It collides head on with #2. Pyodide is CPython 3.14, so a reader running the browser tier gets
Falsefor257 is 257while the prose, written against the pin, saysTrue. This is exactly the small contradiction that #2 warns destroys trust, and it lands in the first part of the book on one of the first things a beginner tries. T08 cannot ship until #2 has an answer.What to do