
On Fri, Dec 24, 2021 at 1:36 PM Steven D'Aprano <steve@pearwood.info> wrote:
My question is, why does it need `@Callable`? Lukasz proposed just using any (undecorated) function, with the convention being that the body is `...` (to which I would add the convention that the function *name* be capitalized, since it is a type).
But without the Callable decorator, it isn't a type, its a function. You're just using it as a type (or to be precise, a function prototype).
I'm okay with naming conventions reflecting usage (we sort of already do that, with int, float, etc) but we should be clear about what's really happening. `def` creates a function.
My reading of this is that a function IS the type of a function with that signature, just like how None means the type NoneType. Is that correct? Or putting it another way: is this (silly) example legal? def repeat_string(s: str, times: int) -> str: return s * times def decimate_strings(lines: Iterable[str], xfrm: repeat_string) -> List[str]: return [xfrm(l, 10) for l in lines] If def creates a function, and def creates the type of a function, it stands to reason that a function is the type of a function. ChrisA