@@ -1679,7 +1679,7 @@ def test_annotation_and_optional_default(self):
16791679 Union ["annotation" , T_default ] : Union [annotation , T_default ],
16801680 Annotated ["annotation" , "nested" ] : Annotated [Union [int , None ], "data" , "nested" ],
16811681 }
1682- if TYPING_3_10_0 : # cannot construct UnionTypes
1682+ if TYPING_3_10_0 : # cannot construct UnionTypes before 3.10
16831683 do_not_stringify_cases ["str | NoneAlias | StrAlias" ] = str | None
16841684 cases [str | None ] = Optional [str ]
16851685 cases .update (do_not_stringify_cases )
@@ -1690,7 +1690,7 @@ def test_annotation_and_optional_default(self):
16901690 skip_reason = None
16911691 annot_unchanged = annot
16921692 if sys .version_info [:2 ] == (3 , 10 ) and annot == "str | NoneAlias | StrAlias" and none_default :
1693- # different repr here as Optional[str | None] -> Optional[str] not a UnionType
1693+ # In 3.10 converts Optional[str | None] to Optional[str] which has a different repr
16941694 skip_reason = "UnionType not preserved in 3.10"
16951695 if wrap_optional :
16961696 if annot_unchanged == ():
@@ -1726,11 +1726,13 @@ def func(x: annot): pass
17261726 # Hash
17271727 for k in type_hints .keys ():
17281728 self .assertEqual (hash (type_hints [k ]), hash (expected [k ]))
1729+ # Test if UnionTypes are preserved
1730+ self .assertEqual (isinstance (type_hints [k ], type (expected [k ])), True )
17291731 # Repr
17301732 with self .subTest ("Check str and repr" ):
17311733 if skip_reason == "UnionType not preserved in 3.10" :
17321734 self .skipTest (skip_reason )
1733- self .assertEqual (str ( type_hints ) + repr (type_hints ), str ( expected ) + repr (expected ))
1735+ self .assertEqual (repr (type_hints ), repr (expected ))
17341736
17351737
17361738class GetUtilitiesTestCase (TestCase ):
0 commit comments