Title: Improve the documentation for `ignore_warnings` · Issue #103109 · python/cpython · GitHub
Open Graph Title: Improve the documentation for `ignore_warnings` · Issue #103109 · python/cpython
X Title: Improve the documentation for `ignore_warnings` · Issue #103109 · python/cpython
Description: Documentation Recently, I found that using ignore_warnings(*, category), a simple decorator in test.support.warning_helper, is sometimes a concise way to suppress warnings in test cases. For example: # use `with` statement def test_suppr...
Open Graph Description: Documentation Recently, I found that using ignore_warnings(*, category), a simple decorator in test.support.warning_helper, is sometimes a concise way to suppress warnings in test cases. For exampl...
X Description: Documentation Recently, I found that using ignore_warnings(*, category), a simple decorator in test.support.warning_helper, is sometimes a concise way to suppress warnings in test cases. For exampl...
Opengraph URL: https://github.com/python/cpython/issues/103109
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve the documentation for `ignore_warnings`","articleBody":"# Documentation\r\n\r\nRecently, I found that using `ignore_warnings(*, category)`, a simple decorator in `test.support.warning_helper`, is sometimes a concise way to suppress warnings in test cases. For example:\r\n\r\n```python\r\n# use `with` statement\r\ndef test_suppress_warning():\r\n with warnings.catch_warnings():\r\n warnings.simplefilter(\"ignore\", category=SyntaxWarning)\r\n # do something\r\n\r\n# use decorator\r\n@warning_helper.ignore_warnings(category=SyntaxWarning)\r\ndef test_suppress_warning():\r\n # do something\r\n```\r\n\r\n**What I want to improve:**\r\n\r\n1. The [comment](https://github.com/python/cpython/blob/e375bff03736f809fbc234010c087ef9d7e0d384/Lib/test/support/warnings_helper.py#L47) of function `ignore_warnings` , it writes\r\n\r\n\u003e Decorator to suppress deprecation warnings\r\n\r\n But in fact this can become a more general warning suppression decorator, not just deprecation warnings, we can improve this comment. \r\n\r\n2. The document of [test.support.warnings_helper](https://docs.python.org/3.12/library/test.html?highlight=warnings_helper#module-test.support.warnings_helper), it is missing information about the function `ignore_warnings`.\r\n3. Perhaps we can also add a default value to it, just like `ignore_warnings(*, category=Warning)`, so that the behavior of this decorator is consistent with `warnings.simplefilter`.\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103110\n* gh-103198\n* gh-103199\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/CharlieZhao95","@type":"Person","name":"CharlieZhao95"},"datePublished":"2023-03-29T11:18:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/103109/cpython/issues/103109"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:23e6bac8-4b05-455f-7265-49630cfc2efa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99C2:3960C0:24BC41:34253B:696A062F |
| html-safe-nonce | 0cf1d441826933f82b59d86ceae6677f08d236e2229079dc157e2ee4742a681e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUMyOjM5NjBDMDoyNEJDNDE6MzQyNTNCOjY5NkEwNjJGIiwidmlzaXRvcl9pZCI6IjM5OTY4MjkzODk4NDI2NzkzNDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eee0bc899edb49b1f31776c107bf8d433cef54c65b12ab6b9917815ef902a027 |
| hovercard-subject-tag | issue:1645587394 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/103109/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3abea1f0f15b792f8879890986047dabdfa1a20dbd25368b0db19ca4827d718f/python/cpython/issues/103109 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3abea1f0f15b792f8879890986047dabdfa1a20dbd25368b0db19ca4827d718f/python/cpython/issues/103109 |
| og:image:alt | Documentation Recently, I found that using ignore_warnings(*, category), a simple decorator in test.support.warning_helper, is sometimes a concise way to suppress warnings in test cases. For exampl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CharlieZhao95 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 578c119ff0247c8b2f2491fbf4fc0395cdf909d4df66598cebdc96ddfc4418dc |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 671c2f67171dbced24284331f3133a613d08c366 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width