-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
`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.
- Loading branch information
Showing
12 changed files
with
263 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# helper to the helper for testing skip_file_prefixes. | ||
|
||
import os | ||
|
||
package_path = os.path.dirname(__file__) | ||
|
||
def inner_api(message, *, stacklevel, warnings_module): | ||
warnings_module.warn( | ||
message, stacklevel=stacklevel, | ||
skip_file_prefixes=(package_path,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2023-01-08-00-12-44.gh-issue-39615.gn4PhB.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:func:`warnings.warn` now has the ability to skip stack frames based on code | ||
filename prefix rather than only a numeric ``stacklevel`` via the new | ||
``skip_file_prefixes`` keyword argument. |
Oops, something went wrong.