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

@ -3113,6 +3113,15 @@ class CAPITests(unittest.TestCase):
self.assertIs(mod, sys.modules[name])
@cpython_only
class TestMagicNumber(unittest.TestCase):
def test_magic_number_endianness(self):
magic_number = (_imp.pyc_magic_number).to_bytes(2, 'little') + b'\r\n'
raw_magic_number = int.from_bytes(magic_number, 'little')
self.assertEqual(raw_magic_number, _imp.pyc_magic_number_token)
if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
unittest.main()