Skip to content

Setting bool values to lineno argument of warnings.filterwarnings() and warnings.simplefilter() works #125899

@hyperkai

Description

@hyperkai

Bug report

Bug description:

Setting the float value 3.14 to lineno argument of warnings.filterwarnings() and warnings.simplefilter() gets the error message as shown below:

import warnings
                                       # ↓ ↓ ↓ ↓ ↓ ↓
warnings.filterwarnings(action="ignore", lineno=3.14) # Error
warnings.simplefilter(action="ignore", lineno=3.14) # Error
                                     # ↑ ↑ ↑ ↑ ↑ ↑
print(warnings.filters)

AssertionError: lineno must be an int >= 0

But setting the bool values True and False to lineno argument of warnings.filterwarnings() and warnings.simplefilter() works as shown below:

import warnings
                                       # ↓ ↓ ↓ ↓ ↓ ↓
warnings.filterwarnings(action="ignore", lineno=True)
warnings.filterwarnings(action="ignore", lineno=False)
                                        # ↑ ↑ ↑ ↑ ↑ ↑
                                     # ↓ ↓ ↓ ↓ ↓ ↓
warnings.simplefilter(action="ignore", lineno=True)
warnings.simplefilter(action="ignore", lineno=False)
                                      # ↑ ↑ ↑ ↑ ↑ ↑
print(warnings.filters)
# [('ignore', None, <class 'Warning'>, None, False),
#  ('ignore', None, <class 'Warning'>, None, True)]

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions