From 76814602740071f2c2329e484ec27158eb68828e Mon Sep 17 00:00:00 2001 From: seanabreau Date: Thu, 24 Sep 2026 17:47:08 -0700 Subject: [PATCH] Test keyword arguments to warnings.warn_explicit Exercise each positional/keyword split with string messages and warning instances in both warnings implementations. Assisted-by: Codex:GPT-6 --- Lib/test/test_warnings/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 5b5d5c2f70ffd7..72dba0c59173b3 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -726,6 +726,27 @@ def test_warn_explicit_non_ascii_filename(self): self.module.warn_explicit("text", UserWarning, filename, 1) self.assertEqual(w[-1].filename, filename) + def test_warn_explicit_keyword_args(self): + names = ('message', 'category', 'filename', 'lineno') + for message, category in (('text', UserWarning), + (UserWarning('text'), None)): + args = (message, category, 'test.py', 42) + for positional_count in range(len(args) + 1): + with self.subTest(message=message, + positional_count=positional_count): + with self.module.catch_warnings(record=True) as w: + self.module.simplefilter('always') + self.module.warn_explicit( + *args[:positional_count], + **dict(zip(names[positional_count:], + args[positional_count:])), + ) + self.assertEqual(len(w), 1) + self.assertEqual(str(w[0].message), 'text') + self.assertIs(w[0].category, UserWarning) + self.assertEqual(w[0].filename, 'test.py') + self.assertEqual(w[0].lineno, 42) + def test_warn_explicit_type_errors(self): # warn_explicit() should error out gracefully if it is given objects # of the wrong types.