Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
gpshead merged 3 commits intopython:mainfromthejcannon:patch-2
May 22, 2025
Merged

Conversation

thejcannon
Copy link
Contributor

@thejcannonthejcannon commentedMay 22, 2025
edited by github-actionsbot
Loading

I love the cleverness and quirkiness of thehashlib 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/

@@ -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:
Copy link
Member

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?

Copy link
ContributorAuthor

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? 🤦

gpshead reacted with laugh emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
>>>withopen("path/to/file","rb")as f:
>>>withopen("Doc/library/hashlib.rst","rb")as f:

Copy link
ContributorAuthor

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

gpshead reacted with laugh emoji
@gpsheadgpshead self-assigned thisMay 22, 2025
@gpsheadgpshead added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes skip issue labelsMay 22, 2025
@gpsheadgpshead merged commit9b292ff intopython:mainMay 22, 2025
28 checks passed
@github-project-automationgithub-project-automationbot moved this fromTodo toDone inDocs PRsMay 22, 2025
@miss-islington-app
Copy link

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 requestMay 22, 2025
(cherry picked from commit9b292ff)Co-authored-by: Josh Cannon <joshdcannon@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 22, 2025
(cherry picked from commit9b292ff)Co-authored-by: Josh Cannon <joshdcannon@gmail.com>
@bedevere-app
Copy link

GH-134549 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 22, 2025
@bedevere-app
Copy link

GH-134550 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 22, 2025
@thejcannonthejcannon deleted the patch-2 branchMay 22, 2025 21:32
gpshead pushed a commit that referenced this pull requestMay 22, 2025
Avoid `__file__` in `hashlib` example (GH-134540)(cherry picked from commit9b292ff)Co-authored-by: Josh Cannon <joshdcannon@gmail.com>
gpshead pushed a commit that referenced this pull requestMay 22, 2025
Avoid `__file__` in `hashlib` example (GH-134540)(cherry picked from commit9b292ff)Co-authored-by: Josh Cannon <joshdcannon@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gpsheadgpsheadgpshead approved these changes

@tirantiranAwaiting requested review from tirantiran is a code owner

@picnixzpicnixzAwaiting requested review from picnixzpicnixz is a code owner

Assignees

@gpsheadgpshead

Labels
docsDocumentation in the Doc dirskip issueskip news
Projects
Status: Done
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@thejcannon@gpshead

[8]ページ先頭

©2009-2025 Movatter.jp