Skip to content

(🐞) Same error reported multiple times on inner functions when show-error-context is enabled #13517

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
KotlinIsland opened this issue Aug 26, 2022 · 1 comment · Fixed by #19247
Labels
bug mypy got something wrong topic-error-reporting How we report errors

Comments

@KotlinIsland
Copy link
Contributor

Doubble trouble

def a() -> None:
    def b() -> None:
        1 + ""
        d

    d = 1
main.py: note: In function "a":
main.py:3: error: Unsupported operand types for + ("int" and "str")
main.py: note: In function "b":
main.py:3: error: Unsupported operand types for + ("int" and "str")

playground

Trippple threat

from typing import TypeVar, overload, _T as T

@overload
def deco(fn: T) -> T: ...
@overload
def deco() -> None: ...

def deco(fn=None): ...


def a() -> None:
    def b() -> None:
        1 + ""
        d
    d = 1
    c()


@deco
def c(): ...
main.py: note: In function "a":
main.py:13: error: Unsupported operand types for + ("int" and "str")
main.py: note: In function "b":
main.py:13: error: Unsupported operand types for + ("int" and "str")
main.py: note: In function "a":
main.py:13: error: Unsupported operand types for + ("int" and "str")

playground

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Aug 26, 2022
@AlexWaygood AlexWaygood added the topic-error-reporting How we report errors label Aug 26, 2022
@sobolevn
Copy link
Member

sobolevn commented Aug 26, 2022

It happens because Errors.remove_duplicates does not consider

main.py:3: error: Unsupported operand types for + ("int" and "str")
main.py: note: In function "b":
main.py:3: error: Unsupported operand types for + ("int" and "str")

as duplicates because of note: In function "b": between them.

tyralla pushed a commit to tyralla/mypy that referenced this issue Jun 10, 2025
Fixes python#19240
Fixes python#13517
Fixes python#17791

Existing de-duplication logic is both complicated and fragile. By
specifying a `parent_error` for a note explicitly, we can do everything
in a more robust and simple way. In addition, this new argument makes
error code matching simpler.
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-error-reporting How we report errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants