gh-122188: Move magic number to its own file (#122243)

* gh-122188: Move magic number to its own file

* Add versionadded directive

* Do work in C

* Integrate launcher.c

* Make _pyc_magic_number private

* Remove metadata

* Move sys.implementation -> _imp

* Modernize comment

* Move _RAW_MAGIC_NUMBER to the C side as well

* _pyc_magic_number -> pyc_magic_number

* Remove unused import

* Update docs

* Apply suggestions from code review

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

* Fix typo in tests

---------

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
Michael Droettboom 2024-07-30 15:31:05 -04:00 committed by GitHub
parent 2b163aa9e7
commit af0a00f022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 307 additions and 295 deletions

View file

@ -5,7 +5,6 @@ from ._bootstrap import _resolve_name
from ._bootstrap import spec_from_loader
from ._bootstrap import _find_spec
from ._bootstrap_external import MAGIC_NUMBER
from ._bootstrap_external import _RAW_MAGIC_NUMBER
from ._bootstrap_external import cache_from_source
from ._bootstrap_external import decode_source
from ._bootstrap_external import source_from_cache
@ -18,7 +17,7 @@ import types
def source_hash(source_bytes):
"Return the hash of *source_bytes* as used in hash-based pyc files."
return _imp.source_hash(_RAW_MAGIC_NUMBER, source_bytes)
return _imp.source_hash(_imp.pyc_magic_number_token, source_bytes)
def resolve_name(name, package):