mirror of
https://github.com/python/cpython.git
synced 2026-01-10 17:30:04 +00:00
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 3ea5332a43)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
03aad3049d
commit
85b58292cf
3 changed files with 36 additions and 16 deletions
|
|
@ -772,6 +772,12 @@ def test_union_parameter_chaining(self):
|
|||
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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue