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

Let overload item have a wider return type than implementation #12434

Closed
JukkaL opened this issue Mar 23, 2022 · 2 comments · Fixed by #12435
Closed

Let overload item have a wider return type than implementation #12434

JukkaL opened this issue Mar 23, 2022 · 2 comments · Fixed by #12435

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 23, 2022

A wider return type can be useful if a decorator gets a more precise error type as part of a typeshed update.

@wrobell reported this concrete example in #12021 (comment):

import typing as tp
from contextlib import asynccontextmanager

T = tp.TypeVar('T')

@tp.overload
def f() -> tp.AsyncContextManager[int]:
    ...

@tp.overload
def f(cls: type[T]) -> tp.AsyncContextManager[T]:
    ...

@asynccontextmanager
async def f(cls=int):
    yield 1

Mypy 0.940 got a more precise type for @asynccontextmanager, and this resulted in apparent false positives:

tp.py:14: error: Overloaded function implementation cannot produce return type of signature 1
tp.py:14: error: Overloaded function implementation cannot produce return type of signature 2

I think that we can allow an overload item to have a more general return type than the implementation, for convenience.

@JukkaL JukkaL added the feature label Mar 23, 2022
@JukkaL JukkaL self-assigned this Mar 23, 2022
JukkaL added a commit that referenced this issue Mar 23, 2022
A wider return type can be useful if a decorator used for the overload
implementation gets a more precise return type as part of a typeshed
update.

Closes #12434.
@pranavrajpal
Copy link
Contributor

This seems like the same issue as #11373.

JukkaL added a commit that referenced this issue Mar 24, 2022
A wider return type can be useful if a decorator used for the overload
implementation gets a more precise return type as part of a typeshed
update.

Closes #12434.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 24, 2022

@pranavrajpal Correct! I also closed #11373.

JukkaL added a commit that referenced this issue Mar 24, 2022
A wider return type can be useful if a decorator used for the overload
implementation gets a more precise return type as part of a typeshed
update.

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

Successfully merging a pull request may close this issue.

3 participants