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

Incompatible return types in overload #4085

Closed
Daenyth opened this issue Oct 9, 2017 · 1 comment
Closed

Incompatible return types in overload #4085

Daenyth opened this issue Oct 9, 2017 · 1 comment

Comments

@Daenyth
Copy link

Daenyth commented Oct 9, 2017

I'm trying to provide a typed interface for async_contextmanager from asyncio_extras in my codebase, and I thought I'd use an overload to address the issue of being arity-agnostic.

I tried this:

from typing import AsyncContextManager, AsyncIterator, Callable, TypeVar, overload
from asyncio_extras import async_contextmanager as _async_contextmanager  # type: ignore

A = TypeVar('A')
B = TypeVar('B')
R = TypeVar('R')

@overload
def async_contextmanager(f: Callable[[A], AsyncIterator[R]]) -> Callable[[A], AsyncContextManager[R]]:
    pass
@overload
def async_contextmanager(f: Callable[[A, B], AsyncIterator[R]]) -> Callable[[A, B], AsyncContextManager[R]]:
    pass
def async_contextmanager(f):
    return _async_contextmanager(f)

And I get

obs/async_contextmanager.py:14: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
obs/async_contextmanager.py:23: error: Function is missing a type annotation

How can I provide an accurate signature here?

@ilevkivskyi
Copy link
Member

I think this is a duplicate of #4020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants