diff --git a/test/typed.py b/test/typed.py index 6b4631c..4323fd9 100755 --- a/test/typed.py +++ b/test/typed.py @@ -2,7 +2,8 @@ import copy from collections.abc import Hashable -from typing import ItemsView, Iterator, KeysView, Mapping, ValuesView +from typing import ItemsView, Iterator, KeysView, Mapping, ValuesView, \ + Union from frozendict import frozendict from typing_extensions import assert_type @@ -21,7 +22,7 @@ assert_type(fd.key(), str) assert_type(fd.value(0), int) assert_type(fd.value(), int) -assert_type(fd.get("a"), int | None) +assert_type(fd.get("a"), Union[int, None]) assert_type(fd.items(), ItemsView[str, int]) assert_type(fd.keys(), KeysView[str]) assert_type(fd.values(), ValuesView[int]) @@ -31,19 +32,32 @@ assert_type(fd.delete("a"), frozendict[str, int]) assert_type(fd | {"c": 2}, frozendict[str, int]) -assert_type(fd | {1: 2}, frozendict[str | int, int]) -assert_type(fd | {"c": "c"}, frozendict[str, str | int]) -assert_type(fd | {1: "c"}, frozendict[str | int, str | int]) +assert_type(fd | {1: 2}, frozendict[Union[str, int], int]) +assert_type(fd | {"c": "c"}, frozendict[str, Union[str, int]]) +assert_type(fd | {1: "c"}, frozendict[Union[str, int], Union[str, int]]) assert_type(fd.setdefault("a", 0), frozendict[str, int]) -assert_type(fd.setdefault("a", "a"), frozendict[str, str | int]) -assert_type(fd.setdefault(0, 0), frozendict[str | int, int]) -assert_type(fd.setdefault(0, "a"), frozendict[str | int, str | int]) +assert_type(fd.setdefault("a", "a"), frozendict[str, Union[str, int]]) +assert_type(fd.setdefault(0, 0), frozendict[Union[str, int], int]) + +assert_type( + fd.setdefault(0, "a"), + frozendict[Union[str, int], Union[str, int]] +) assert_type(fd.set("abc", 1), frozendict[str, int]) -assert_type(fd.set("abc", "abc"), frozendict[str, str | int]) -assert_type(fd.set(1, 1), frozendict[str | int, int]) -assert_type(fd.set(1, "abc"), frozendict[str | int, str | int]) + +assert_type( + fd.set("abc", "abc"), + frozendict[str, Union[str, int]] +) + +assert_type(fd.set(1, 1), frozendict[Union[str, int], int]) + +assert_type( + fd.set(1, "abc"), + frozendict[Union[str, int], Union[str, int]] +) # frozendict implements Mapping[K, V] and is covariant in V vals: frozendict[str, Hashable] = fd