When a warning is encountered by the mechanisms of the warnings module, it uses issubclass checks on its type against the warning filters previously inserted. This makes tuples of warning classes as the category argument to warnings.simplefilter acceptable as well, but the current annotations .
Standard library example of this usage on the main branch, in Lib/codeop.py, under the _maybe_compile helper function:
# Disable compiler warnings when checking for incomplete input.
with warnings.catch_warnings():
warnings.simplefilter("ignore", (SyntaxWarning, DeprecationWarning))
try:
compiler(source, filename, symbol, flags=flags)
except SyntaxError: # Let other compile() errors propagate.
try:
compiler(source + "\n", filename, symbol, flags=flags)
return None
except _IncompleteInputError:
return None
except SyntaxError:
pass
# fallthrough
The analogous parameter in the warnings.catch_warnings constructor, introduced in Python 3.11 and added to typeshed by #7685, is passed straight through to warnings.simplefilter. Its type should be updated accordingly.
When a warning is encountered by the mechanisms of the
warningsmodule, it usesissubclasschecks on its type against the warning filters previously inserted. This makes tuples of warning classes as thecategoryargument towarnings.simplefilteracceptable as well, but the current annotations .Standard library example of this usage on the main branch, in
Lib/codeop.py, under the_maybe_compilehelper function:The analogous parameter in the
warnings.catch_warningsconstructor, introduced in Python 3.11 and added to typeshed by #7685, is passed straight through towarnings.simplefilter. Its type should be updated accordingly.