Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Avoid__file__
inhashlib
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
Doc/library/hashlib.rst Outdated
@@ -284,7 +284,7 @@ a file or file-like object. | |||
Example: | |||
>>> 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 evencleverer 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.
>>>withopen("path/to/file","rb")as f: | |
>>>withopen("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
9b292ff
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@thejcannon for the PR, and@gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
GH-134549 is a backport of this pull request to the3.14 branch. |
GH-134550 is a backport of this pull request to the3.13 branch. |
Uh oh!
There was an error while loading.Please reload this page.
I love the cleverness and quirkiness of the
hashlib
documentation choosing to hash thehashlib
module 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/