Skip to content

"Overloaded ... incompatible return types" error when one overloaded argument is a Tuple #4237

Closed

Description

@joshstaiger

Running mypy (0.550) on the following code:

from typing import overload, Tuple, Any

class A: ...
class B: ...
class C: ...
class D: ...

@overload
def f(x: A) -> B: ...

@overload
def f(x: Tuple[C]) -> D: ...

def f(x: Any) -> Any:...

reports:

error: Overloaded function signatures 1 and 2 overlap with incompatible return types

I've tried a couple different types for the second overload and so far the error only seems to occur with Tuple[...] arguments. For instance, I don't see the issue if I substitute def f(x:List[C]) -> D: ... as the 2nd overload.

Activity

  1. gvanrossum commented on Nov 13, 2017

    @gvanrossum
    Member

    Yeah, this looks like a bug. I'm not sure where to look. Strangely it perseveres if I use Tuple[C, C] or Tuple[Any] but it is gone with Tuple or tuple.

  2. elazarg commented on Nov 13, 2017

    @elazarg
    Contributor

    is_overlapping_types() does not check for tuple types, and

    We conservatively assume that non-instance, non-union, and non-TypeType types can overlap any other types.

  3. gvanrossum commented on Nov 13, 2017

    @gvanrossum
    Member

    Yeah, still looks like a bug. That comment is not a specification.

  4. elazarg commented on Nov 13, 2017

    @elazarg
    Contributor

    Of course.

  5. added a commit that references this issue on Nov 24, 2017
    e180c7c
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 wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions