From 9370e1916039f4a8c1cbf12a060a484180cef59d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 18 Feb 2022 21:55:12 -0800 Subject: [PATCH 1/2] bpo-46066: catch DeprecationWarning --- Lib/test/test_typing.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index b38e27c5f90471..b9e7a809f17379 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4585,8 +4585,12 @@ def test_typeddict_create_errors(self): with self.assertRaises(TypeError): TypedDict(_typename='Emp', name=str, id=int) - with self.assertRaises(TypeError): - TypedDict('Emp', _fields={'name': str, 'id': int}) + + # We raise a DeprecationWarning for the keyword syntax + # before the TypeError. + with self.assertWarns(DeprecationWarning): + with self.assertRaises(TypeError): + TypedDict('Emp', _fields={'name': str, 'id': int}) def test_typeddict_errors(self): Emp = TypedDict('Emp', {'name': str, 'id': int}) @@ -4598,8 +4602,11 @@ def test_typeddict_errors(self): isinstance(jim, Emp) with self.assertRaises(TypeError): issubclass(dict, Emp) - with self.assertRaises(TypeError): - TypedDict('Hi', x=1) + # We raise a DeprecationWarning for the keyword syntax + # before the TypeError. + with self.assertWarns(DeprecationWarning): + with self.assertRaises(TypeError): + TypedDict('Hi', x=1) with self.assertRaises(TypeError): TypedDict('Hi', [('x', int), ('y', 1)]) with self.assertRaises(TypeError): From a0de62523338d721750f255c6c9f9cd340d92932 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 19 Feb 2022 07:57:35 -0800 Subject: [PATCH 2/2] Update Lib/test/test_typing.py --- Lib/test/test_typing.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index b9e7a809f17379..dc1514d63b7775 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4585,12 +4585,6 @@ def test_typeddict_create_errors(self): with self.assertRaises(TypeError): TypedDict(_typename='Emp', name=str, id=int) - - # We raise a DeprecationWarning for the keyword syntax - # before the TypeError. - with self.assertWarns(DeprecationWarning): - with self.assertRaises(TypeError): - TypedDict('Emp', _fields={'name': str, 'id': int}) def test_typeddict_errors(self): Emp = TypedDict('Emp', {'name': str, 'id': int})