Skip to content

First overload picked overeagerly when overloading on self type #14070

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

Open
JelleZijlstra opened this issue Nov 12, 2022 · 1 comment
Open

First overload picked overeagerly when overloading on self type #14070

JelleZijlstra opened this issue Nov 12, 2022 · 1 comment
Labels
bug mypy got something wrong topic-overloads

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Nov 12, 2022

Consider this example:

from typing import Generic, TypeVar, Any, overload

AnyStr = TypeVar("AnyStr", str, bytes)

class Popen(Generic[AnyStr]):
    @overload
    def communicate(self: Popen[str], buf: str = ...) -> float: ...
    @overload
    def communicate(self: Popen[bytes], buf: memoryview | bytes = ...) -> range: ...
    def communicate(self, buf: object = None) -> Any: raise NotImplementedError

p = Popen()
reveal_type(p.communicate())

This currently reveals float. I think it should either be the union float | range or Any. This came up in python/typeshed#9100.

@mr-c
Copy link
Contributor

mr-c commented Feb 5, 2025

I can confirm that this is still an issue with mypy 1.15, especially for mypyc users when subprocess.Popen (or similar) is called with stdout=subprocess.DEVNULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-overloads
Projects
None yet
Development

No branches or pull requests

2 participants