Skip to content

bpo-44279: [doc] reword contextlib.suppress documentation #26428

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

Merged
merged 3 commits into from
Jun 1, 2021
Merged

bpo-44279: [doc] reword contextlib.suppress documentation #26428

merged 3 commits into from
Jun 1, 2021

Conversation

MapleCCC
Copy link
Contributor

@MapleCCC MapleCCC commented May 28, 2021

The document of contextlib.suppress does make it sound like it would suppress any specified exception. It would be better if we inform the user that the overarching promise doesn't include warnings, which are also exceptions, albeit special.

https://bugs.python.org/issue44279

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@MapleCCC

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label May 28, 2021
@iritkatriel
Copy link
Member

I don't follow. It will suppress DeprecationWarning if you raise it:

>>> import contextlib
>>> raise DeprecationWarning(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
DeprecationWarning: 42
>>> with contextlib.suppress(DeprecationWarning):
...     raise DeprecationWarning(42)
... 
>>> 

@MapleCCC
Copy link
Contributor Author

MapleCCC commented May 29, 2021

@iritkatriel I think per the doc of warnings, the typical way of issuing warnings is through the warnings.warn() function instead of directly raising it.

>>> import contextlib, warnings
>>> with contextlib.suppress(DeprecationWarning):
...     warnings.warn("Something is deprecated", DeprecationWarning)
...
<stdin>:2: DeprecationWarning: Something is deprecated
>>>

@iritkatriel
Copy link
Member

@iritkatriel I think per the doc of warnings, the typical way of issuing warnings is through the warnings.warn() function instead of directly raising it.

>>> import contextlib, warnings
>>> with contextlib.suppress(DeprecationWarning):
...     warnings.warn("Something is deprecated", DeprecationWarning)
...
<stdin>:2: DeprecationWarning: Something is deprecated
>>>

That's correct, so the exception is not raised. The documentation states that suppress is equivalent to try: ... except: pass. That wouldn't suppress a warning.warn() either. warnings has its own suppression api: https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings

Perhaps it would be clearer if in the first sentence it said "exceptions if they are raised in the body" instead of "exceptions if they occur in the body".

@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

@iritkatriel Yes, that makes more sense. Now that we are settled that this pull request is not suitable, I would close it. Thank you for the kind reply!

@MapleCCC MapleCCC closed this Jun 1, 2021
@iritkatriel
Copy link
Member

Would you like to create a new one changing "if they occur" to "if they are raised"?

@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

@iritkatriel I would like to but my signed CLA is still long waiting to get processed. The waiting is a bit tedious. So I think perhaps it's better you just change it directly with no PR. After all, the change is brought up by you, and I don't want to take the credit. Thanks!

@iritkatriel
Copy link
Member

The CLA shouldn't take a long time. Are you sure you linked your bugs.python.org account with your github account correctly?

@iritkatriel
Copy link
Member

Also, you don't need a new PR. We can reopen this one and replace the change.

@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

I re-checked the b.p.o. account, the email and the signed PDF document. Yes it should be correct. On second thought, I did not write a very detailed address on the CLA form out of privacy concern; not sure whether that is a problem.

Also, you don't need a new PR. We can reopen this one and replace the change.

Ok, I am doing it.

@MapleCCC MapleCCC reopened this Jun 1, 2021
@iritkatriel
Copy link
Member

I re-checked the b.p.o. account, the email and the signed PDF document. Yes it should be correct. On second thought, I did not write a very detailed address on the CLA form out of privacy concern; not sure whether that is a problem.

@Mariatta Are you able to check what's happening with the CLA? If it's not you, then who can?

@MapleCCC MapleCCC closed this Jun 1, 2021
…xceptions, but not warnings issued by warnings.warn()
@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

@iritkatriel Thanks for the help. The system finally confirms that I have signed the CLA. Everything is set and the PR is ready to get merged. Anytime when you are okay.

@iritkatriel iritkatriel changed the title Supplement that contextlib.suppress won't suppress warnings bpo-44279: [doc] reword contextlib.suppress documentation for better clarity Jun 1, 2021
@iritkatriel iritkatriel changed the title bpo-44279: [doc] reword contextlib.suppress documentation for better clarity bpo-44279: [doc] reword contextlib.suppress documentation Jun 1, 2021
@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

I notice that there are some hyperlinks in the contextlib.rst that look like the following:

:keyword:`!with`

with an additional exclamation mark. It this normal? Got to admit that I am not very familiar with the reStructuredText syntax.

@iritkatriel
Copy link
Member

I notice that there are some hyperlinks in the contextlib.rst that look like the following:

:keyword:`!with`

with an additional exclamation mark. It this normal? Got to admit that I am not very familiar with the reStructuredText syntax.

If you add ! then it's not a link, just a different font. See here:
https://devguide.python.org/documenting/#rest-inline-markup

@iritkatriel
Copy link
Member

Maybe in this case it makes sense to put !s, because this whole doc is about context managers so a lot of links to with are just clutter.

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

You can just click the button to accept these changes in your PR.

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 1, 2021

Thanks for the information and tips. I was not very familiar with the GitHub web UI. Your suggested changes are done, through the web UI.

@iritkatriel iritkatriel added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Jun 1, 2021
@iritkatriel iritkatriel merged commit 87272b7 into python:main Jun 1, 2021
iritkatriel pushed a commit to iritkatriel/cpython that referenced this pull request Jun 1, 2021
…honGH-26428)

(cherry picked from commit 87272b7)

Co-authored-by: MapleCCC <littlelittlemaple@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Jun 1, 2021
@bedevere-bot
Copy link

GH-26480 is a backport of this pull request to the 3.10 branch.

iritkatriel pushed a commit to iritkatriel/cpython that referenced this pull request Jun 1, 2021
…onGH-26428)

(cherry picked from commit 87272b7)

Co-authored-by: MapleCCC <littlelittlemaple@gmail.com>
@bedevere-bot
Copy link

GH-26481 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Jun 1, 2021
@iritkatriel
Copy link
Member

Thank you @MapleCCC , welcome to CPython!

iritkatriel added a commit that referenced this pull request Jun 1, 2021
…26428) (GH-26480)

(cherry picked from commit 87272b7)

Co-authored-by: MapleCCC <littlelittlemaple@gmail.com>
iritkatriel added a commit that referenced this pull request Jun 1, 2021
…6428) (GH-26481)

(cherry picked from commit 87272b7)

Co-authored-by: MapleCCC <littlelittlemaple@gmail.com>
@MapleCCC
Copy link
Contributor Author

MapleCCC commented Jun 2, 2021

@iritkatriel Oh, thank you! I learned a lot. Happy that the PR goes well. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants