From c01b478d43e1be2e7c41a6a636b0f6bfc61444e9 Mon Sep 17 00:00:00 2001 From: Bonifacio de Oliveira Date: Sat, 12 Jun 2021 17:13:02 -0300 Subject: [PATCH 1/4] add category type check Co-authored-by: Vajrasky Kok --- Lib/test/test_warnings/__init__.py | 7 +++++++ Lib/warnings.py | 1 + 2 files changed, 8 insertions(+) diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 4b1b4e193cb165b..e2becb74a1c1afc 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -342,6 +342,13 @@ def test_filterwarnings_duplicate_filters(self): "the beginning of list" ) + def test_simplefilter_invalid_category(self): + with original_warnings.catch_warnings(record=True, module=self.module): + invalid_category = 'spam' + with self.assertRaises(AssertionError) as cm: + self.module.simplefilter("once", invalid_category) + self.assertEqual(str(cm.exception), "category must be a class") + def test_simplefilter_duplicate_filters(self): with original_warnings.catch_warnings(module=self.module): self.module.resetwarnings() diff --git a/Lib/warnings.py b/Lib/warnings.py index 691ccddfa450ad2..5df7c8c29a7cc90 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -176,6 +176,7 @@ def simplefilter(action, category=Warning, lineno=0, append=False): "once"), "invalid action: %r" % (action,) assert isinstance(lineno, int) and lineno >= 0, \ "lineno must be an int >= 0" + assert isinstance(category, type), "category must be a class" _add_filter(action, None, category, None, lineno, append=append) def _add_filter(*item, append): From db698e4a88b56b7687587f06298ef5daac858a0b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 12 Jun 2021 20:21:41 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst diff --git a/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst new file mode 100644 index 000000000000000..ac2eae903796616 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst @@ -0,0 +1 @@ +add category type check to warnings.simplefilter \ No newline at end of file From 90ec5db3dd7480f97efc4988062aec1655dab4d4 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com> Date: Sun, 13 Jun 2021 10:11:07 -0300 Subject: [PATCH 3/4] Update 2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst --- .../next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst index ac2eae903796616..b6856266e841da6 100644 --- a/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst +++ b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst @@ -1 +1 @@ -add category type check to warnings.simplefilter \ No newline at end of file +Add category type check to `warnings.simplefilter`. From 291fdcc9a1aa431f9e83ebf21f42c9a432c2cc20 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:41:29 -0300 Subject: [PATCH 4/4] Update 2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst --- .../next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst index b6856266e841da6..8678300e12a5db6 100644 --- a/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst +++ b/Misc/NEWS.d/next/Library/2021-06-12-20-21-40.bpo-16845.SqR6Ik.rst @@ -1 +1 @@ -Add category type check to `warnings.simplefilter`. +Add category type check to warnings.simplefilter.