cachew
cachew copied to clipboard
infer_type does not work for return type Optional[]
It seems that an optional return type does not work as expected. Extending the test case in def test_optional(tdir): results in an error:
@cachew(tdir)
def data() -> Optional[Job]:
return None
Error:
...
@cachew(tdir)
> def data() -> Optional[Job]:
test_cachew.py:497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../__init__.py:694: in <lambda>
return lambda realf: f(realf, *args, **kwargs)
../__init__.py:789: in cachew
inferred = infer_type(func)
../__init__.py:667: in infer_type
if not issubclass(rtype.__origin__, Iterable):
/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py:835: in __subclasscheck__
return issubclass(cls, self.__origin__)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'collections.abc.Iterable'>, subclass = typing.Union
def __subclasscheck__(cls, subclass):
"""Override for issubclass(subclass, cls)."""
> return _abc_subclasscheck(cls, subclass)
E TypeError: issubclass() arg 1 must be a class