FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-159739: Fix reference and error handling in warnings (GH-159758) by jelle-openai · Pull Request #160085 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions Lib/test/test_warnings/__init__.py
This file contains hidden or 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
Expand Up @@ -663,6 +663,19 @@ def test_skip_file_prefixes_type_errors(self):
with self.assertRaises(TypeError):
warn("msg", skip_file_prefixes="a sequence of strs")

def test_skip_file_prefixes_empty_tuple_subclass(self):
with warnings_state(self.module):
self.module.simplefilter("always")
warn = warning_tests.warnings.warn
class EmptyTuple(tuple):
pass
# Passing an empty tuple subclass used to lead to a crash.
for _ in range(3):
with self.module.catch_warnings(record=True) as w:
warn("msg", skip_file_prefixes=EmptyTuple())
self.assertEqual(len(w), 1)
self.assertEqual(w[-1].filename, __file__)

def test_exec_filename(self):
filename = "<warnings-test>"
codeobj = compile(("import warnings\n"
Expand Down
This file contains hidden or 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,2 @@
Fix a crash in :func:`warnings.warn` when ``skip_file_prefixes`` is an empty tuple subclass.
Propagate allocation errors when creating the fallback filename.
4 changes: 3 additions & 1 deletion Python/_warnings.c
This file contains hidden or 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
Expand Up @@ -1093,6 +1093,9 @@ setup_context(Py_ssize_t stack_level,
if (f == NULL) {
globals = interp->sysdict;
*filename = PyUnicode_FromString("<sys>");
if (*filename == NULL) {
return 0;
}
*lineno = 0;
}
else {
Expand Down Expand Up @@ -1237,7 +1240,6 @@ warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
stacklevel = 2;
}
} else {
Py_DECREF((PyObject *)skip_file_prefixes);
skip_file_prefixes = NULL;
}
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL