1414 TYPE_CHECKING ,
1515 Any ,
1616 Literal ,
17- TypeAliasType ,
1817 cast ,
1918 get_args ,
2019 get_origin ,
@@ -46,6 +45,7 @@ def orjson_dumps(*args, **kwargs): # type: ignore[misc]
4645from .utils import (
4746 CachewException ,
4847 TypeNotSupported ,
48+ resolve_type_parameters ,
4949)
5050
5151# in case of changes in the way cachew stores data, this should be changed to discard old caches
@@ -119,15 +119,15 @@ def infer_return_type(func) -> Failure | Inferred:
119119 ... return None if len(s) == 0 else s[0]
120120 >>> kind, opt = infer_return_type(first_character)
121121 >>> # in 3.8, Optional[str] is printed as Union[str, None], so need to hack around this
122- >>> (kind, opt is Optional[str])
122+ >>> (kind, opt == Optional[str])
123123 ('single', True)
124124
125125 # tuple is an iterable.. but presumably should be treated as a single value
126126 >>> from typing import Tuple
127127 >>> def a_tuple() -> Tuple[int, str]:
128128 ... return (123, 'hi')
129129 >>> infer_return_type(a_tuple)
130- ('single', typing.Tuple [int, str])
130+ ('single', tuple [int, str])
131131
132132 >>> from typing import Collection, NamedTuple
133133 >>> class Person(NamedTuple):
@@ -169,14 +169,14 @@ def infer_return_type(func) -> Failure | Inferred:
169169 ... yield 1
170170 ... yield 'aaa'
171171 >>> infer_return_type(iterator_str_int)
172- ('multiple', Str | Int )
172+ ('multiple', str | int )
173173
174174 # a bit of an edge case
175175 >>> from typing import Tuple
176176 >>> def empty_tuple() -> Iterator[Tuple[()]]:
177177 ... yield ()
178178 >>> infer_return_type(empty_tuple)
179- ('multiple', typing.Tuple [()])
179+ ('multiple', tuple [()])
180180
181181 ... # doctest: +ELLIPSIS
182182
@@ -196,7 +196,7 @@ def infer_return_type(func) -> Failure | Inferred:
196196 >>> def unsupported_list() -> List[Custom]:
197197 ... return [Custom()]
198198 >>> infer_return_type(unsupported_list)
199- "can't infer type from typing.List [cachew.Custom]: can't cache <class 'cachew.Custom'>"
199+ "can't infer type from list [cachew.Custom]: can't cache <class 'cachew.Custom'>"
200200 """
201201 try :
202202 hints = get_type_hints (func )
@@ -208,9 +208,7 @@ def infer_return_type(func) -> Failure | Inferred:
208208 if rtype is None :
209209 return f"no return type annotation on { func } "
210210
211- if isinstance (rtype , TypeAliasType ):
212- # handle 'type ... = ...' aliases
213- rtype = rtype .__value__
211+ rtype = resolve_type_parameters (rtype )
214212
215213 def bail (reason : str ) -> str :
216214 return f"can't infer type from { rtype } : " + reason
0 commit comments