Skip to content

warnings.warn(...) arguments include '\*', which is wrong - 3.12 #114811

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
scotscotmcc opened this issue Jan 31, 2024 · 2 comments
Closed

warnings.warn(...) arguments include '\*', which is wrong - 3.12 #114811

scotscotmcc opened this issue Jan 31, 2024 · 2 comments
Labels
3.12 only security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error

Comments

@scotscotmcc
Copy link
Contributor

scotscotmcc commented Jan 31, 2024

Documentation

Looking at the online python docs at https://docs.python.org/3.11/library/warnings.html#warnings.warn. The function call is listed on the site like this:

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

As far as I know (my apologies if I am very wrong), \* isn't a valid argument, and it should just be *.

Best guess is that since the actual code (here) has a linebreak in the arguments, that linebreak got formatted for the docs as a \*.

I saw this all come up in this stackoverflow question where other people thought it all through, i'm just posting the issue.

This seems to be new in 3.12

Linked PRs

@scotscotmcc scotscotmcc added the docs Documentation in the Doc dir label Jan 31, 2024
@hugovk
Copy link
Member

hugovk commented Jan 31, 2024

Thank you for the report!

Yep, this shows up at https://docs.python.org/3/library/warnings.html#warnings.warn but not https://docs.python.org/3.11/library/warnings.html#warnings.warn

Looking at the code:

cpython/Lib/warnings.py

Lines 297 to 298 in 3e06cce

def warn(message, category=None, stacklevel=1, source=None,
*, skip_file_prefixes=()):

You're right, this should just be *.

This means the arguments to the right of the asterisk are keyword-only.

I guess the original author added the slash in an attempt to escape it, but it's actually not needed here.

Would you like to make a PR to fix it?

The file to fix is https://github.com/python/cpython/blob/main/Doc/library/warnings.rst

@hugovk hugovk added easy 3.12 only security fixes 3.13 bugs and security fixes labels Jan 31, 2024
terryjreedy pushed a commit that referenced this issue Feb 1, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 1, 2024
Regression in 3.12.
(cherry picked from commit ff8939e)

Co-authored-by: Pradyot Ranjan <[email protected]>
@terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Feb 1, 2024
terryjreedy pushed a commit that referenced this issue Feb 1, 2024
…4837)

Regression in 3.12.
(cherry picked from commit ff8939e)

Co-authored-by: Pradyot Ranjan <[email protected]>
@terryjreedy
Copy link
Member

Thanks for catching and patching the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants