On Thu, Dec 23, 2021 at 05:09:18PM -0800, Guido van Rossum wrote:

> >     def func(params)
> >
> > makes a Callable type object?
> >
> 
> No, no, no. That syntax has already been discredited.

It has? Where? Have I missed something?

This thread is about using that syntax as an alternative to Mark's
proposal. If it is already ruled out, then somebody should mention it 
to asleep.cult (the original poster of this thread).

I'm curious: what objections to asleep.cult's proposal don't equally 
apply to Mark's proposal? From what I can see, Mark's original proposal 
has all the same disadvantages, plus it is even more verbose.

Dropping the need for the @Callable decorator reduces the level of 
verbosity somewhat (one less line, nine fewer characters) but all the 
other negatives remain.

Honestly, I cannot see a single positive to using `def` statements. 
Sure, we can do it, and an experienced programmer could infer the 
meaning of it, but given the choice of writing an anonymous type in 
place where you want it, versus having to pre-declare a function 
prototype with a name that adds nothing to the readability of the code 
before using it, why would I prefer the `def` version?

This is not a rhetorical question.

The fact that the existing feature (Callable) and the PEP 677 arrow 
syntax are anonymous, and can be written in place rather than needing to 
be pre-declared with a name, are positives. *Requiring* a name to use 
this `def` syntax is a point against it.

If I need a named type alias, I can already create one, and name it:

    IntToIntFunc = Callable[[int], int]

and while I can see that there are complicated signatures where a named 
alias would be useful:

    FileOpener = Callable[ ... ] # complicated signature

we can already do that, so the `def` syntax adds nothing. For simple 
cases we don't need a name. The name IntToIntFunc adds nothing that 
isn't just as clear, if not more so, in the signature itself. It is like 
the comment:

    x += 1  # add one to x


> Mark's proposal was
> ```
> @Callable
> def func(params): pass
> ```

Indeed, and I already wrote a criticism of that proposal.

Removing the decorator saves one line and nine characters, but the other 
criticisms remain.


> 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.


-- 
Steve
_______________________________________________
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/VTOOJLPU2HPIW6TQBBYTW64W4DFGCQEG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to