| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I figured this issue was simple enough to warrant not opening a bug or issue, let me know if I was mistaken. |
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
| def myfunction(arg, ignore_exceptions=False): | ||
| if ignore_exceptions: | ||
| # Use suppress to ignore all exceptions. | ||
| cm = contextlib.suppress(BaseException) |
There was a problem hiding this comment.
Suppressing KeyboardInterrupt and SystemExit is almost never the right thing to do, so the example exception here should only be Exception (not BaseException)
Sorry, something went wrong.
…ythonGH-8158) Include a more easily understood example for nullcontext (cherry picked from commit c287545) Co-authored-by: Daniel Porteous <danielporteous1@gmail.com>
|
GH-8199 is a backport of this pull request to the 3.7 branch. |
Sorry, something went wrong.
|
Awesome, super happy to help. Thanks! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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