From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:06:38 +0000 (-0700) Subject: bpo-44353: Add test to cover __or__ of two NewType (GH-27259) (#27261) X-Git-Tag: v3.10.0rc1~92 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ae5ba7dbf08d56a1b30d67fcde75532fe136d77;p=thirdparty%2FPython%2Fcpython.git bpo-44353: Add test to cover __or__ of two NewType (GH-27259) (#27261) (cherry picked from commit 4868b94c6089d457673b1ba5b5b64c2f38c435af) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com> --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 3a28be1d7f56..f5abbb29db64 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -3692,12 +3692,15 @@ class NewTypeTests(BaseTestCase): def test_or(self): UserId = NewType('UserId', int) + UserName = NewType('UserName', str) - self.assertEqual(UserId | int, Union[UserId, int]) - self.assertEqual(int | UserId, Union[int, UserId]) + for cls in (int, UserName): + with self.subTest(cls=cls): + self.assertEqual(UserId | cls, Union[UserId, cls]) + self.assertEqual(cls | UserId, Union[cls, UserId]) - self.assertEqual(get_args(UserId | int), (UserId, int)) - self.assertEqual(get_args(int | UserId), (int, UserId)) + self.assertEqual(get_args(UserId | cls), (UserId, cls)) + self.assertEqual(get_args(cls | UserId), (cls, UserId)) def test_special_attrs(self): UserId = NewType('UserId', int)