Skip to content

Overload with Dict only checks overlap on keys #9451

Closed
@rhshadrach

Description

@rhshadrach

Using mypy 0.782, it looks like overlap is only checked on dictionary keys.

from typing import Dict, overload

class A: pass
class B: pass

@overload
def foo(x: Dict[A, A]) -> A: ...

@overload
def foo(x: Dict[A, B]) -> B: ...

def foo(x):
    for k, v in x: return v
    raise ValueError

gives error: Overloaded function signatures 1 and 2 overlap with incompatible return types. I get the same error when using Mapping instead of `Dict.

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