Skip to content

Commit ebe7e6d

Browse files
miss-islingtonambv
andauthored
bpo-44852: Support filtering over warnings without a set message (GH-27793) (GH-27810)
Additional improvements: - messages which were compiled regular expressions aren't unpacked back into strings for unmatched warnings; - removed unnecessary "if tokens:" check (there's one before the for loop); - took `endswith` calculation out of the for loop. (cherry picked from commit 8cf07d3) Co-authored-by: Łukasz Langa <[email protected]>
1 parent e2320c6 commit ebe7e6d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/test/support/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,13 +3257,14 @@ def clear_ignored_deprecations(*tokens: object) -> None:
32573257
raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
32583258

32593259
new_filters = []
3260+
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
32603261
for action, message, category, module, lineno in warnings.filters:
32613262
if action == "ignore" and category is DeprecationWarning:
32623263
if isinstance(message, re.Pattern):
3263-
message = message.pattern
3264-
if tokens:
3265-
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
3266-
if message.endswith(endswith):
3264+
msg = message.pattern
3265+
else:
3266+
msg = message or ""
3267+
if msg.endswith(endswith):
32673268
continue
32683269
new_filters.append((action, message, category, module, lineno))
32693270
if warnings.filters != new_filters:

0 commit comments

Comments
 (0)