summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-07-18 11:59:25 (GMT)
committerGitHub <noreply@github.com>2021-07-18 11:59:25 (GMT)
commit85b58292cf94de74d028053ac33a65f269f305cb (patch)
tree304937fd8c945ea985e8208da171bb9d097561b7 /Lib
parent03aad3049d1591c76a219dfe089e5367f88f167e (diff)
downloadcpython-85b58292cf94de74d028053ac33a65f269f305cb.zip
cpython-85b58292cf94de74d028053ac33a65f269f305cb.tar.gz
cpython-85b58292cf94de74d028053ac33a65f269f305cb.tar.bz2
bpo-44633: Fix parameter substitution of the union type with wrong types. (GH-27218) (GH-27224)
A TypeError is now raised instead of returning NotImplemented. (cherry picked from commit 3ea5332a4365bdd771286b3e9692495116e9ceef) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index b2e1130..6ed7471 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -772,6 +772,12 @@ class UnionTests(unittest.TestCase):
self.assertEqual((list[T] | list[S])[int, T], list[int] | list[T])
self.assertEqual((list[T] | list[S])[int, int], list[int])
+ def test_union_parameter_substitution_errors(self):
+ T = typing.TypeVar("T")
+ x = int | T
+ with self.assertRaises(TypeError):
+ x[42]
+
def test_or_type_operator_with_forward(self):
T = typing.TypeVar('T')
ForwardAfter = T | 'Forward'