Skip to content

Commit d1c0e44

Browse files
miss-islingtonambv
andauthored
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. (cherry picked from commit 8cf07d3db3eed02b43350a5f9dbf68f1c839ea82) Co-authored-by: Łukasz Langa <[email protected]>
1 parent bbb1076 commit d1c0e44

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

20612061
new_filters = []
2062+
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
20622063
for action, message, category, module, lineno in warnings.filters:
20632064
if action == "ignore" and category is DeprecationWarning:
20642065
if isinstance(message, re.Pattern):
2065-
message = message.pattern
2066-
if tokens:
2067-
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
2068-
if message.endswith(endswith):
2066+
msg = message.pattern
2067+
else:
2068+
msg = message or ""
2069+
if msg.endswith(endswith):
20692070
continue
20702071
new_filters.append((action, message, category, module, lineno))
20712072
if warnings.filters != new_filters:

0 commit comments

Comments
 (0)