Skip to content

Setting many types of values to category argument of warnings.simplefilter() doesn't get any error #125893

Open
@hyperkai

Description

@hyperkai

Bug report

Bug description:

Setting Warning to category argument of warnings.filterwarnings() works, then setting the str type value "Hello World" to category argument of warnings.filterwarnings() gets the error message as shown below. *This is an understandable behavior:

import warnings

warnings.resetwarnings()

warnings.filterwarnings(action="ignore", category=Warning)

print(warnings.filters)
# [('ignore', None, <class 'Warning'>, None, 0)]

warnings.filterwarnings(action="ignore", category="Hello World") # Error

print(warnings.filters)

AssertionError: category must be a class

But, setting many types of values to category argument of warnings.simplefilter() doesn't get any error as shown below. *This isn't an understandable behavior:

import warnings

warnings.simplefilter(action="default", category=Warning)         # Understandable
warnings.simplefilter(action="default", category="Hello World") # Not understandable
warnings.simplefilter(action="default", category=100)                 # Not understandable
warnings.simplefilter(action="default", category=3.14)                # Not understandable
warnings.simplefilter(action="default", category=3.14+0.j)          # Not understandable
warnings.simplefilter(action="default", category=True)                # Not understandable

print(warnings.filters)
# [('default', None, True, None, 0),
#  ('default', None, (3.14+0j), None, 0),
#  ('default', None, 100, None, 0),
#  ('default', None, 'Hello World', None, 0),
#  ('default', None, <class 'Warning'>, None, 0)]

So, category argument of warnings.simplefilter() should also return the error message as shown below:

AssertionError: category must be a class

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy