Setting many types of values to `category` argument of `warnings.simplefilter()` doesn't get any error
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den im Report gezeigten Einstiegspunkten warnings.simplefilter() und warnings.filterwarnings() und vergleiche, wie jeder seinen category-Parameter validiert. Reproduziere die Beispiele mit ungültigen Werten und bestätige, dass simplefilter() denselben Fehler bei der Kategorievalidierung auslöst wie filterwarnings().
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100