
On Fri, Dec 24, 2021 at 01:54:35PM +1100, Chris Angelico wrote:
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?
That's not the status quo, but I think the idea is that it will be. Except that I think that the preferred terminology is that it is a *function prototype* rather than a type, since it is a prototype, not an actual class you can instantiate. A template, if you will: "Any callable with the same signature (modulo parameter names) as this template / protocol is acceptable."
Or putting it another way: is this (silly) example legal? [snip example]
I think maybe it should be, but right now, mypy reports it as illegal: [steve ~]$ mypy ~/func_prototype.py /home/steve/func_prototype.py:7: error: Function "func_prototype.repeat_string" is not valid as a type If we allow this, I see no reason why functions used as prototypes should be required to have an empty body. (Ellipsis or pass.) I think that actual, useful functions with an implementation should be allowed, as in your example. -- Steve