Skip to content

Error merging nested overloads #12606

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

Closed
cdce8p opened this issue Apr 17, 2022 · 0 comments · Fixed by #12607
Closed

Error merging nested overloads #12606

cdce8p opened this issue Apr 17, 2022 · 0 comments · Fixed by #12607
Labels
bug mypy got something wrong topic-overloads

Comments

@cdce8p
Copy link
Collaborator

cdce8p commented Apr 17, 2022

Bug Report

Mypy can't merge nested overloads. Those can happen if all are wrapped with if TYPE_CHECKING and combined with a nested conditional overload.

https://mypy.readthedocs.io/en/stable/more_types.html#conditional-overloads

=> I'm working on a fix already and plan to open a PR soon.

To Reproduce

from typing import overload

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

@overload
def f1(g: A) -> A: ...
if True:
    @overload
    def f1(g: B) -> B: ...
    if True:
        @overload
        def f1(g: C) -> C: ...
        @overload
        def f1(g: D) -> D: ...
def f1(g): ...

Expected Behavior

Overloads should merge just fine.

reveal_type(f1(A()))  # N: Revealed type is "__main__.A"
reveal_type(f1(B()))  # N: Revealed type is "__main__.B"
reveal_type(f1(C()))  # N: Revealed type is "__main__.C"
reveal_type(f1(D()))  # N: Revealed type is "__main__.D"

Actual Behavior

test.py:8: error: Single overload definition, multiple required
test.py:11: error: Name "f1" already defined on line 8
test.py:11: error: An overloaded function outside a stub file must have an implementation
test.py:18: error: Name "f1" already defined on line 8

Your Environment

  • Mypy version used: mypy 0.960+dev.44993e6a18f852a9296786267ecf26ea730b4f31
  • Mypy command-line flags: mypy test2.py --always-true True --always-false False
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

Successfully merging a pull request may close this issue.

2 participants