Skip to content

mypy reports the wrong line number for decorator issues #18391

@A5rocks

Description

@A5rocks

Bug Report

If a decorator fails to apply, then the error gets noted as the start of the decorator chain.

I expected to find an issue already made about this, but I found nothing. I would not be surprised if this is a duplicate though.

To Reproduce

from collections.abc import Callable

def faulty(c: Callable[[int], None]) -> Callable[[tuple[int, int]], None]:
    return lambda x: None
    
@faulty  # 2 errors reported here
@faulty
def f(x: str) -> None:
    return None

Interestingly, if faulty returns Callable[[str], None] this only reports 1 error. I assume this is an artifact of error deduplication.

Expected Behavior

Different line numbers.

Actual Behavior

Same line numbers.

Your Environment

Checked on mypy playground.

  • Mypy version used: v1.14
  • Mypy command-line flags: strict
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12

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