Skip to content
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

Setting None to skip_file_prefixes of warnings.warn() gets error #125818

Closed
hyperkai opened this issue Oct 21, 2024 · 3 comments
Closed

Setting None to skip_file_prefixes of warnings.warn() gets error #125818

hyperkai opened this issue Oct 21, 2024 · 3 comments
Labels
docs Documentation in the Doc dir

Comments

@hyperkai
Copy link

hyperkai commented Oct 21, 2024

Bug report

Bug description:

The doc of warnings.warn() says skip_file_prefixes is None by default as shown below:

warnings.warn(message, category=None, stacklevel=1, source=None, *, skip_file_prefixes=None)

But, setting None to skip_file_prefixes gets the error as shown below:

import warnings

warnings.warn(message='Warning',
              category=None,
              stacklevel=1,
              source=None,
              skip_file_prefixes=None) # Error
            # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑

TypeError: warn() argument 'skip_file_prefixes' must be tuple, not None

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

@hyperkai hyperkai added the type-bug An unexpected behavior, bug, or error label Oct 21, 2024
@tomasr8
Copy link
Member

tomasr8 commented Oct 21, 2024

This is probably just a typo in the docs. The default value for that parameter as actually an empty tuple:

cpython/Lib/warnings.py

Lines 302 to 316 in 4848b0b

def warn(message, category=None, stacklevel=1, source=None,
*, skip_file_prefixes=()):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
if not (isinstance(category, type) and issubclass(category, Warning)):
raise TypeError("category must be a Warning subclass, "
"not '{:s}'".format(type(category).__name__))
if not isinstance(skip_file_prefixes, tuple):
# The C version demands a tuple for implementation performance.
raise TypeError('skip_file_prefixes must be a tuple of strs.')

(It's also the case for the C module) The docs mention it too:

[...] If supplied, it must be a tuple of strings.

Would you like to open a PR to fix the method signature in the docs?

@tomasr8 tomasr8 added docs Documentation in the Doc dir and removed type-bug An unexpected behavior, bug, or error labels Oct 21, 2024
@rruuaanng
Copy link
Contributor

Maybe the task of repairing this document can be entrusted to me.
If there is no comment, I will launch a PR.

willingc pushed a commit that referenced this issue Oct 31, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 31, 2024
…xes` in warnings docs (pythonGH-125823)

Change documentation
(cherry picked from commit d467d92)

Co-authored-by: RUANG (James Roy) <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 31, 2024
…xes` in warnings docs (pythonGH-125823)

Change documentation
(cherry picked from commit d467d92)

Co-authored-by: RUANG (James Roy) <[email protected]>
willingc pushed a commit that referenced this issue Oct 31, 2024
…ixes` in warnings docs (GH-125823) (GH-126217)

gh-125818: Fix incorrect signature of argument `skip_file_prefixes` in warnings docs (GH-125823)

Change documentation
(cherry picked from commit d467d92)

Co-authored-by: RUANG (James Roy) <[email protected]>
willingc pushed a commit that referenced this issue Oct 31, 2024
…ixes` in warnings docs (GH-125823) (#126216)

gh-125818: Fix incorrect signature of argument `skip_file_prefixes` in warnings docs (GH-125823)

Change documentation
(cherry picked from commit d467d92)

Co-authored-by: RUANG (James Roy) <[email protected]>
@erlend-aasland
Copy link
Contributor

Thanks for the report, Kai, and thanks for the PR, James.

picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
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
Projects
Status: Todo
Development

No branches or pull requests

4 participants