GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — First overload picked overeagerly when overloading on self type · Issue #14070 · python/mypy

First overload picked overeagerly when overloading on self type #14070

New issue
Copy link
New issue
Copy link
Open
Open
First overload picked overeagerly when overloading on self type#14070
Copy link
Labels
bugmypy got something wrongtopic-overloads

Description

@JelleZijlstra
JelleZijlstra
opened on Nov 12, 2022
Issue body actions

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.

Reacted by Joren Hammudoglu

Activity

  1. JelleZijlstra
    added
    bugmypy got something wrong
    topic-overloads
    on Nov 12, 2022
  2. mr-c commented on Feb 5, 2025

    @mr-c
    mr-c
    on Feb 5, 2025
    Contributor
    More actions

    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

    Reacted by Joren Hammudoglu
  3. ilevkivskyi commented on Sep 20, 2026

    @ilevkivskyi
    ilevkivskyi
    on Sep 20, 2026
    Member
    More actions

    Btw I think a bigger issue (in this particular example) is that we randomly choose first constraint when a type argument is not given instead of Any (i.e. reveal_type(p) gives Popen[str] in this example). Changing this may be risky, but something that we could potentially try at some point.

    The overload selection part will be fixed by #22011 when it is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-overloads

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.