gh-39615: Add warnings.warn() skip_file_prefixes support (#100840)

`warnings.warn()` gains the ability to skip stack frames based on code
filename prefix rather than only a numeric `stacklevel=` via a new
`skip_file_prefixes=` keyword argument.
This commit is contained in:
Gregory P. Smith 2023-01-27 18:35:14 -08:00 committed by GitHub
parent 8cef9c0f92
commit 052f53d65d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 264 additions and 49 deletions

View file

@ -1,9 +1,15 @@
# Helper module for testing the skipmodules argument of warnings.warn()
# Helper module for testing stacklevel and skip_file_prefixes arguments
# of warnings.warn()
import warnings
from test.test_warnings.data import package_helper
def outer(message, stacklevel=1):
inner(message, stacklevel)
def inner(message, stacklevel=1):
warnings.warn(message, stacklevel=stacklevel)
def package(message, *, stacklevel):
package_helper.inner_api(message, stacklevel=stacklevel,
warnings_module=warnings)