FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-34067: Include a more easily understood example for nullcontext by banool · Pull Request #8158 · python/cpython · GitHub

Repository navigation

bpo-34067: Include a more easily understood example for nullcontext - #8158

Merged
ncoghlan merged 2 commits into
python:masterfrom
banool:master
Jul 9, 2018
Merged

ncoghlan merged 2 commits into
python:masterfrom
banool:master

Conversation

banool commented Jul 7, 2018 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

When trying to let a few friends know about contextlib.nullcontext, they "didn't get it" based on the example in the docs. I feel that including examples that do and don't use enter_result can help new users understand the intention of nullcontext as a no-op context manager.

I also noticed that normally italics are used for an argument, so I fixed that up on line 155.

https://bugs.python.org/issue34067

banool commented Jul 7, 2018

Copy link
Copy Markdown
Contributor Author

I figured this issue was simple enough to warrant not opening a bug or issue, let me know if I was mistaken.

serhiy-storchaka requested a review from ncoghlan July 9, 2018 11:58
ncoghlan changed the title Docs: Include a more easily understood example for nullcontext bpo-34067: Include a more easily understood example for nullcontext Jul 9, 2018

ncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I like this addition, with one small tweak to the exception type being suppressed (which I'll edit in directly).

I've also associated it with an issue we already have open, pointing out some other problems with the current nullcontext example.

Comment thread Doc/library/contextlib.rst Outdated
def myfunction(arg, ignore_exceptions=False):
if ignore_exceptions:
# Use suppress to ignore all exceptions.
cm = contextlib.suppress(BaseException)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Suppressing KeyboardInterrupt and SystemExit is almost never the right thing to do, so the example exception here should only be Exception (not BaseException)

ncoghlan merged commit c287545 into python:master Jul 9, 2018

Copy link
Copy Markdown
Contributor

Thanks @banool for the PR, and @ncoghlan for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 9, 2018
…ythonGH-8158)

Include a more easily understood example for nullcontext
(cherry picked from commit c287545)

Co-authored-by: Daniel Porteous <danielporteous1@gmail.com>

Copy link
Copy Markdown

GH-8199 is a backport of this pull request to the 3.7 branch.

banool commented Jul 9, 2018

Copy link
Copy Markdown
Contributor Author

Awesome, super happy to help. Thanks!

miss-islington added a commit that referenced this pull request Jul 9, 2018
…H-8158)

Include a more easily understood example for nullcontext
(cherry picked from commit c287545)

Co-authored-by: Daniel Porteous <danielporteous1@gmail.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL