]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44852: Support filtering over warnings without a set message (GH-27793) (GH-27810)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 18 Aug 2021 12:10:39 +0000 (05:10 -0700)
committerGitHub <noreply@github.com>
Wed, 18 Aug 2021 12:10:39 +0000 (14:10 +0200)
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 <lukasz@langa.pl>
Lib/test/support/__init__.py

index 39dea88076e9e1c90a8a9930eadd115446fa5eef..7e5a29b18de393df03d56828cdfc372e19014842 100644 (file)
@@ -3257,13 +3257,14 @@ def clear_ignored_deprecations(*tokens: object) -> None:
         raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
 
     new_filters = []
+    endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
     for action, message, category, module, lineno in warnings.filters:
         if action == "ignore" and category is DeprecationWarning:
             if isinstance(message, re.Pattern):
-                message = message.pattern
-            if tokens:
-                endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
-            if message.endswith(endswith):
+                msg = message.pattern
+            else:
+                msg = message or ""
+            if msg.endswith(endswith):
                 continue
         new_filters.append((action, message, category, module, lineno))
     if warnings.filters != new_filters: