-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Avoid __file__ in hashlib example
#134540
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
Doc/library/hashlib.rst
Outdated
|
|
||
| >>> import io, hashlib, hmac | ||
| >>> with open(hashlib.__file__, "rb") as f: | ||
| >>> with open("path/to/file", "rb") as f: |
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.
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?
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.
Oh, now its even cleverer in that this was hand-picked because we know its gonna pass doctest? 🤦
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.
| >>> with open("path/to/file", "rb") as f: | |
| >>> with open("Doc/library/hashlib.rst", "rb") as f: |
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.
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
|
Thanks @thejcannon for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
(cherry picked from commit 9b292ff) Co-authored-by: Josh Cannon <[email protected]>
(cherry picked from commit 9b292ff) Co-authored-by: Josh Cannon <[email protected]>
|
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. |
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/