Skip to content

Setting an int type value to category argument of warnings.warn() gets a wrong error message #125854

@hyperkai

Description

@hyperkai

Bug report

Bug description:

Setting the int type value 100 to category argument of warnings.warn() gets the error message as shown below:

import warnings
                                         # ↓ ↓ Here ↓ ↓
warnings.warn(message='This is a warning', category=100) # Error

TypeError: category must be a Warning subclass, not 'int'

But the superclass Warning also works as shown below:

import warnings
                                         # ↓ ↓ ↓ Here ↓ ↓ ↓
warnings.warn(message='This is a warning', category=Warning)
# Warning: This is a warning
#   warnings.warn(message='This is a warning', category=Warning)

So, the error message should be something like as shown below:

TypeError: category must be a Warning superclass or Warning subclass, not 'int'

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython 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