Skip to content

Commit 7799a15

Browse files
committed
Add more tests to cover types.Union
1 parent 1a1ac84 commit 7799a15

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/test/test_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,13 @@ def test_or_type_operator_with_TypeVar(self):
668668

669669
def test_union_parameter_chaining(self):
670670
T = typing.TypeVar("T")
671+
S = typing.TypeVar("S")
671672

672673
self.assertEqual((float | list[T])[int], float | list[int])
673674
self.assertEqual(list[int | list[T]].__parameters__, (T,))
674675
self.assertEqual(list[int | list[T]][str], list[int | list[str]])
676+
self.assertEqual((list[T] | list[S]).__parameters__, (T, S))
677+
self.assertEqual((list[T] | list[S])[int, T], list[int] | list[T])
675678

676679
def test_or_type_operator_with_forward(self):
677680
T = typing.TypeVar('T')

Objects/unionobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static PyObject *
443443
union_getitem(PyObject *self, PyObject *item)
444444
{
445445
unionobject *alias = (unionobject *)self;
446-
// do a lookup for __parameters__ so it gets populated (if not already)
446+
// Populate __parameters__ if needed.
447447
if (alias->parameters == NULL) {
448448
alias->parameters = _Py_make_parameters(alias->args);
449449
if (alias->parameters == NULL) {

0 commit comments

Comments
 (0)