-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-122188: Move magic number to its own file #122243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
can be named after the Python major version of the magic number bump, but | ||
it can really be anything, as long as it's different than anything else | ||
that's come before. The tags are included in the following table, starting | ||
with Python 3.2a0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved this comment here from the other file, but I did notice this last sentence seems to be no longer true. There are two 3.2 magic tags mentioned below but that's it. I think it's just entirely based on version number now. Does it make sense to remove this paragraph?
Python/sysmodule.c
Outdated
value = PyLong_FromLong(PYC_MAGIC_NUMBER); | ||
if (value == NULL) | ||
goto error; | ||
res = PyDict_SetItemString(impl_info, "pyc_magic_number", value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if sys.implementation
is the best place for this? https://docs.python.org/3/library/sys.html#sys.implementation has all attributes being required for all implementations and bytecode is not necessary to implement Python. Should it just be a private attribute in sys instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to those docs, this can't be added as sys.implementation.pyc_magic_number
without a PEP. sys.implementation._pyc_magic_number
(left undocumented) would be fine, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made this private.
4fd9ea6
to
f7d8a42
Compare
Thanks for making the requested changes! @ericsnowcurrently: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for moving that.
There's one small thing left to do.
When you're done making the requested changes, leave the comment: |
I have made the requested changes; please review again Note, I've added a test to make sure that the new C-side calculation of |
Thanks for making the requested changes! @ericsnowcurrently: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I've left a small number of minor suggestions related to formatting and tests. I'm approving the PR assuming you will address those (one way or another).
MAGIC_NUMBER = (3603).to_bytes(2, 'little') + b'\r\n' | ||
|
||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c | ||
MAGIC_NUMBER = (_imp.pyc_magic_number).to_bytes(2, 'little') + b'\r\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be defined as:
MAGIC_NUMBER = _imp.pyc_magic_number_token.to_bytes(4, 'little')
And _imp.pyc_magic_number
will no longer be used, it can be removed. See #122503.
* pythongh-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 <[email protected]> * Fix typo in tests --------- Co-authored-by: Eric Snow <[email protected]>
Lib/importlib/_bootstrap_external.py
#122188📚 Documentation preview 📚: https://cpython-previews--122243.org.readthedocs.build/