Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infer_type does not work for return type Optional[] #29

Closed
Ebolon opened this issue Jul 6, 2021 · 0 comments
Closed

infer_type does not work for return type Optional[] #29

Ebolon opened this issue Jul 6, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@Ebolon
Copy link

Ebolon commented Jul 6, 2021

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/python@3.9/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
@karlicoss karlicoss added the bug Something isn't working label Sep 3, 2021
karlicoss added a commit that referenced this issue Sep 13, 2023
simplifies code by reusing existing marshalling routings

in addition enables support for #29 (needs a bit more work though)
karlicoss added a commit that referenced this issue Sep 13, 2023
simplifies code by reusing existing marshalling routings

in addition enables support for #29 (needs a bit more work though)
karlicoss added a commit that referenced this issue Sep 13, 2023
simplifies code by reusing existing marshalling routings

in addition enables support for #29 (needs a bit more work though)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants