On Fri, Dec 24, 2021 at 1:36 PM Steven D'Aprano <st...@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
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/KJFQEMO73IP7UIIN2UX74OKKHBAIDN6X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to