Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renumber magic
  • Loading branch information
youknowone committed Jan 19, 2026
commit 0f2639b15837c73e6214e012b0e8d822cf48067e
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (2997).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (2996).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_magic_number(self):
# stakeholders such as OS package maintainers must be notified
# in advance. Such exceptional releases will then require an
# adjustment to this test case.
EXPECTED_MAGIC_NUMBER = 2997
EXPECTED_MAGIC_NUMBER = 2996
actual = int.from_bytes(importlib.util.MAGIC_NUMBER[:2], 'little')

msg = (
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn get_git_datetime() -> String {
}

// Must be aligned to Lib/importlib/_bootstrap_external.py
pub const PYC_MAGIC_NUMBER: u16 = 2997;
pub const PYC_MAGIC_NUMBER: u16 = 2996;
Comment on lines 131 to +132
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

CPython 3.14 pyc magic number

💡 Result:

CPython 3.14 pyc magic number: 3627 (4-byte magic token = b'\x2b\x0e\x0d\x0a'). [1][2]

Sources:

  • Include/internal/pycore_magic_number.h (PYC_MAGIC_NUMBER = 3627). [1]
  • Explanation of pyc magic/token format (little-endian 2-byte number + CR LF). [2]

Change PYC_MAGIC_NUMBER to 3627 to match CPython 3.14.

Line 132 sets the value to 2996, but CPython 3.14's magic number is 3627 (defined in Include/internal/pycore_magic_number.h). Using the incorrect value will cause RustPython to misread .pyc files from CPython 3.14.

🤖 Prompt for AI Agents
In `@crates/vm/src/version.rs` around lines 131 - 132, The constant
PYC_MAGIC_NUMBER is set incorrectly to 2996; update the value of pub const
PYC_MAGIC_NUMBER in version.rs to 3627 so it matches CPython 3.14's magic number
(as defined in CPython's pycore_magic_number) to ensure .pyc files from CPython
3.14 are read correctly.


// CPython format: magic_number | ('\r' << 16) | ('\n' << 24)
// This protects against text-mode file reads
Expand Down
Loading