@@ -10,25 +10,20 @@ extern "C" {
10
10
11
11
/*
12
12
13
- Magic word to reject .pyc files generated by other Python versions.
13
+ Magic number to reject .pyc files generated by other Python versions.
14
14
It should change for each incompatible change to the bytecode.
15
15
16
+ PYC_MAGIC_NUMBER must change whenever the bytecode emitted by the compiler may
17
+ no longer be understood by older implementations of the eval loop (usually due
18
+ to the addition of new opcodes).
19
+
16
20
The value of CR and LF is incorporated so if you ever read or write
17
21
a .pyc file in text mode the magic number will be wrong; also, the
18
22
Apple MPW compiler swaps their values, botching string constants.
19
23
20
- There were a variety of old schemes for setting the magic number.
21
- The current working scheme is to increment the previous value by
22
- 10.
23
-
24
- Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic
25
- number also includes a new "magic tag", i.e. a human readable string used
26
- to represent the magic number in __pycache__ directories. When you change
27
- the magic number, you must also set a new unique magic tag. Generally this
28
- can be named after the Python major version of the magic number bump, but
29
- it can really be anything, as long as it's different than anything else
30
- that's come before. The tags are included in the following table, starting
31
- with Python 3.2a0.
24
+ There were a variety of old schemes for setting the magic number. Starting with
25
+ Python 3.11, Python 3.n starts with magic number 2900+50n. Within each minor
26
+ version, the magic number is incremented by 1 each time the file format changes.
32
27
33
28
Known values:
34
29
Python 1.5: 20121
@@ -86,9 +81,7 @@ Known values:
86
81
introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE
87
82
#4715)
88
83
Python 3.2a1: 3160 (add SETUP_WITH #6101)
89
- tag: cpython-32
90
84
Python 3.2a2: 3170 (add DUP_TOP_TWO, remove DUP_TOPX and ROT_FOUR #9225)
91
- tag: cpython-32
92
85
Python 3.2a3 3180 (add DELETE_DEREF #4617)
93
86
Python 3.3a1 3190 (__class__ super closure changed)
94
87
Python 3.3a1 3200 (PEP 3155 __qualname__ added #13448)
@@ -269,14 +262,8 @@ Known values:
269
262
You should always use the *upcoming* tag. For example, if 3.12a6 came out
270
263
a week ago, I should put "Python 3.12a7" next to my new magic number.
271
264
272
- MAGIC must change whenever the bytecode emitted by the compiler may no
273
- longer be understood by older implementations of the eval loop (usually
274
- due to the addition of new opcodes).
275
-
276
- Starting with Python 3.11, Python 3.n starts with magic number 2900+50n.
277
-
278
- Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
279
- in PC/launcher.c must also be updated.
265
+ Whenever PYC_MAGIC_NUMBER is changed, the ranges in the magic_values array in
266
+ PC/launcher.c must also be updated.
280
267
281
268
*/
282
269
0 commit comments