[Python-checkins] bpo-44852: Support filtering over warnings without a set message (GH-27793)

miss-islington webhook-mailer at python.org
Wed Aug 18 08:10:32 EDT 2021


https://github.com/python/cpython/commit/d1c0e4413dd544270df1f5b8a145fd4370cb759b
commit: d1c0e4413dd544270df1f5b8a145fd4370cb759b
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-08-18T05:10:10-07:00
summary:

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 <lukasz at langa.pl>

files:
M Lib/test/support/__init__.py

diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 227ce47655f98..abc2a189ffc5f 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2059,13 +2059,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:



More information about the Python-checkins mailing list