mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Improve decorator type error message for decorated functions (#16295)

Open LeoLomardo opened this issue 1 month ago • 3 comments

This PR is related with the issue #16295

Checklist:

  • Clarifies error reporting when a decorator (or decorator factory) supplies an incompatible callable signature, including the decorated function’s name.
  • Adds regression test for decorator factory application to verify the detailed message.

LeoLomardo avatar Dec 08 '25 23:12 LeoLomardo

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/client/schemas/objects.py:306: error: Argument 1 has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]
+ src/prefect/client/schemas/objects.py:306: error: Decorated function "result" has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]

github-actions[bot] avatar Dec 08 '25 23:12 github-actions[bot]

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/client/schemas/objects.py:306: error: Argument 1 has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]
+ src/prefect/client/schemas/objects.py:306: error: Decorated function "result" has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]

github-actions[bot] avatar Dec 09 '25 14:12 github-actions[bot]

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/client/schemas/objects.py:306: error: Argument 1 has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]
+ src/prefect/client/schemas/objects.py:306: error: Decorated function "result" has incompatible type "Callable[[State[R], bool, bool], R | Exception]"; expected "Callable[[State[R], Literal[True], bool], R]"  [arg-type]

github-actions[bot] avatar Dec 09 '25 16:12 github-actions[bot]