Skip to content

Improve the documentation for ignore_warnings #103109

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

Closed
CharlieZhao95 opened this issue Mar 29, 2023 · 1 comment
Closed

Improve the documentation for ignore_warnings #103109

CharlieZhao95 opened this issue Mar 29, 2023 · 1 comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@CharlieZhao95
Copy link
Contributor

CharlieZhao95 commented Mar 29, 2023

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_suppress_warning():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=SyntaxWarning)
        # do something

# use decorator
@warning_helper.ignore_warnings(category=SyntaxWarning)
def test_suppress_warning():
    # do something

What I want to improve:

  1. The comment of function ignore_warnings , it writes

Decorator to suppress deprecation warnings

But in fact this can become a more general warning suppression decorator, not just deprecation warnings, we can improve this comment.

  1. The document of test.support.warnings_helper, it is missing information about the function ignore_warnings.
  2. 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.

Linked PRs

@CharlieZhao95 CharlieZhao95 added the docs Documentation in the Doc dir label Mar 29, 2023
@arhadthedev arhadthedev added tests Tests in the Lib/test dir type-feature A feature request or enhancement and removed docs Documentation in the Doc dir labels Mar 30, 2023
erlend-aasland pushed a commit that referenced this issue Apr 2, 2023
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 2, 2023
…onGH-103110)

(cherry picked from commit 32937d6)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 2, 2023
…onGH-103110)

(cherry picked from commit 32937d6)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
@erlend-aasland
Copy link
Contributor

Fixing the docstring and adding documentation seems enough for now. AFAIK, there is no need for adding a default value (consistency with warnings.simplefilter is not reason enough IMO). Marking this as closed.

miss-islington added a commit that referenced this issue Apr 2, 2023
(cherry picked from commit 32937d6)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
miss-islington added a commit that referenced this issue Apr 2, 2023
(cherry picked from commit 32937d6)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
gaogaotiantian pushed a commit to gaogaotiantian/cpython that referenced this issue Apr 8, 2023
…on#103110)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
warsaw pushed a commit to warsaw/cpython that referenced this issue Apr 11, 2023
…on#103110)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants