Skip to content

Commit 8cf07d3

Browse files
authored
bpo-44852: Support filtering over warnings without a set message (GH-27793)
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.
1 parent 3240bc6 commit 8cf07d3

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
@@ -2070,13 +2070,14 @@ def clear_ignored_deprecations(*tokens: object) -> None:
20702070
raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
20712071

20722072
new_filters = []
2073+
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
20732074
for action, message, category, module, lineno in warnings.filters:
20742075
if action == "ignore" and category is DeprecationWarning:
20752076
if isinstance(message, re.Pattern):
2076-
message = message.pattern
2077-
if tokens:
2078-
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
2079-
if message.endswith(endswith):
2077+
msg = message.pattern
2078+
else:
2079+
msg = message or ""
2080+
if msg.endswith(endswith):
20802081
continue
20812082
new_filters.append((action, message, category, module, lineno))
20822083
if warnings.filters != new_filters:

0 commit comments

Comments
 (0)