Avoid __file__ in hashlib example#134540
Merged
gpshead merged 3 commits intopython:mainfrom May 22, 2025
Merged
Conversation
gpshead
reviewed
May 22, 2025
Doc/library/hashlib.rst
Outdated
|
|
||
| >>> import io, hashlib, hmac | ||
| >>> with open(hashlib.__file__, "rb") as f: | ||
| >>> with open("path/to/file", "rb") as f: |
Member
There was a problem hiding this comment.
the previous code worked because it passes doctest. It probably runs from the repo root, what happens if you use "Doc/library/hashlib.rst" here?
Contributor
Author
There was a problem hiding this comment.
Oh, now its even cleverer in that this was hand-picked because we know its gonna pass doctest? 🤦
Contributor
Author
There was a problem hiding this comment.
Suggested change
| >>> with open("path/to/file", "rb") as f: | |
| >>> with open("Doc/library/hashlib.rst", "rb") as f: |
Contributor
Author
There was a problem hiding this comment.
FileNotFoundError: [Errno 2] No such file or directory: 'Doc/library/hashlib.rst'
https://github.com/python/cpython/actions/runs/15196498586/job/42741793385?pr=134540#step:8:405
gpshead
approved these changes
May 22, 2025
|
Thanks @thejcannon for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
May 22, 2025
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
May 22, 2025
|
GH-134549 is a backport of this pull request to the 3.14 branch. |
|
GH-134550 is a backport of this pull request to the 3.13 branch. |
Pranjal095
pushed a commit
to Pranjal095/cpython
that referenced
this pull request
Jul 12, 2025
taegyunkim
pushed a commit
to taegyunkim/cpython
that referenced
this pull request
Aug 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I love the cleverness and quirkiness of the
hashlibdocumentation choosing to hash thehashlibmodule itself, however it is exactly that: "clever" and "quirky". Unfortunately, I've seen Python newbies and intermediates struggling to understand this example when trying to hash files themselves (not the least because the example doeshashlib.__file__and not__file__orsome_other_module.__file__).So, let's move to something more "obvious" 👍 at the cost of being a slightly less silly place 👎
Open question to the room on whether this should be backported.
📚 Documentation preview 📚: https://cpython-previews--134540.org.readthedocs.build/