Skip to content

Commit ff502b6

Browse files
Support an internal plain text default filter.
1 parent 67b7fb9 commit ff502b6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Lib/_py_warnings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ def warn(message, category=None, stacklevel=1, source=None,
522522

523523
def _match_filename(pattern, filename, *, MS_WINDOWS=(sys.platform == 'win32')):
524524
if not filename:
525+
print(repr(pattern))
525526
return pattern.match('<unknown>') is not None
526527
if filename[0] == '<' and filename[-1] == '>':
527528
return pattern.match(filename) is not None

Python/_warnings.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,20 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg, PyObject
180180
if (obj == Py_None)
181181
return 1;
182182

183-
if (arg != NULL) {
184-
/* An internal plain text default filter must match exactly */
185-
if (PyUnicode_CheckExact(obj)) {
186-
int cmp_result = PyUnicode_Compare(obj, arg);
187-
if (cmp_result == -1 && PyErr_Occurred()) {
188-
return -1;
189-
}
190-
return !cmp_result;
183+
/* An internal plain text default filter must match exactly */
184+
if (PyUnicode_CheckExact(obj)) {
185+
if (arg == NULL) {
186+
return 0;
187+
}
188+
int cmp_result = PyUnicode_Compare(obj, arg);
189+
if (cmp_result == -1 && PyErr_Occurred()) {
190+
return -1;
191191
}
192+
return !cmp_result;
193+
}
192194

193-
/* Otherwise assume a regex filter and call its match() method */
195+
/* Otherwise assume a regex filter and call its match() method */
196+
if (arg != NULL) {
194197
result = PyObject_CallMethodOneArg(obj, &_Py_ID(match), arg);
195198
}
196199
else {

0 commit comments

Comments
 (0)