This is such a great idea that I think it deserves its own PEP (to compete with this one?) Let me explain. PEP 677 was created for the sole purpose of replacing typing.Callable, but there are still some other areas where function metadata is required. What if we instead introduced a function prototype that allows you to "declare" a "function" without a body.
typing example:
import typing
@typing.Callable
def IntToIntFunc(a: int) -> int
def flat_map(
l: list[int],
func: IntToIntFunc
) -> list[int]:
...
ctypes example:
import ctypes
@ctypes.CFUNCTYPE
def f(x: int) -> bool
But of course this comes with a few issues: should it be an expression and if so, should the name be optional? How can ParamSpec be handled?
Allowing 'def' without a body based on the presence or absence of a decorator sounds like it will just confuse people and cause bizarre errors if people accidentally leave out a body. Let's not go there.
However, Lukasz has already proposed a very similar mechanism (with dummy body), without needing a decorator. His proposal is simply:
def IntToIntFunc(a: int) -> int: ...
def flat_map(l: list[int], func: IntToIntFunc) -> list[int]:
# body
No need for a `@Callable` decorator!