Alternative syntax for Callable type-hinting
Hello, The idea here is to use the same operator already used to type-hint the return of functions `->` to define the return of a Callable. * Current syntax: Callable[[ArgumentList], ReturnType] eg. def x(method: Callable[[int, dict], None]) -> None: pass * Proposed syntax: Callable[ArgumentList] -> ReturnType eg. def x(method: Callable[int, dict] -> None) -> None: pass Do you think this is more intuitive? Is it viable? Kind regards, Thiago
On Tue, Jul 28, 2020 at 05:42 Thiago Carvalho D' Ávila < thiagocavila@gmail.com> wrote:
The idea here is to use the same operator already used to type-hint the return of functions `->` to define the return of a Callable.
* Current syntax:
Callable[[ArgumentList], ReturnType]
eg.
def x(method: Callable[[int, dict], None]) -> None: pass
* Proposed syntax:
Callable[ArgumentList] -> ReturnType
eg.
def x(method: Callable[int, dict] -> None) -> None: pass
Why not just ‘(int, dict) -> None’? Do you think this is more intuitive? Is it viable?
Definitively more intuitive. With the new PEG parser it *may* be viable. However it may make it harder in the future to introduce ‘(x, y) -> x+y’ as a shorthand for lambda, which has also been proposed. I wouldn’t rush anything. —Guido -- --Guido (mobile)
I also like that one, both more intuitive than current syntax I think.
On Tue, 28 Jul 2020, 11:25 Guido van Rossum,
On Tue, Jul 28, 2020 at 05:42 Thiago Carvalho D' Ávila < thiagocavila@gmail.com> wrote:
The idea here is to use the same operator already used to type-hint the return of functions `->` to define the return of a Callable.
* Current syntax:
Callable[[ArgumentList], ReturnType]
eg.
def x(method: Callable[[int, dict], None]) -> None: pass
* Proposed syntax:
Callable[ArgumentList] -> ReturnType
eg.
def x(method: Callable[int, dict] -> None) -> None: pass
Why not just ‘(int, dict) -> None’?
Do you think this is more intuitive? Is it viable?
Definitively more intuitive. With the new PEG parser it *may* be viable.
However it may make it harder in the future to introduce ‘(x, y) -> x+y’ as a shorthand for lambda, which has also been proposed.
I wouldn’t rush anything.
—Guido -- --Guido (mobile)
participants (2)
-
Guido van Rossum
-
Thiago Carvalho D' Ávila