python / python/cpython

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

Abierto
#125,893 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

3.12 3.13 3.14 stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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
  • gh-136303
  • gh-136305

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con los puntos de entrada warnings.simplefilter() y warnings.filterwarnings() mostrados en el informe, comparando cómo cada uno valida su argumento category. Reproduce los ejemplos con valores no válidos y confirma que simplefilter() genera el mismo error de validación de category que filterwarnings().

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.