Hi,
Why not make Callable usable as a function decorator?
The motivating example in the PEP is this:
def flat_map(
l: list[int],
func: Callable[[int], list[int]]
) -> list[int]:
....
Since, as the PEP claims, `Callable[[int], list[int]]` is hard to read, then
give it a name and use regular function definition syntax.
@Callable
def IntToIntFunc(a:int)->int:
pass
def flat_map(
l: list[int],
func: IntToIntFunc
) -> list[int]:
....
To me, this seems much clearer than the proposed syntax and is more general.
It is a little longer, but unless you are playing code golf, that shouldn't
matter.
Cheers,
Mark.
On 16/12/2021 5:57 pm, Steven Troxler wrote:
Hello all,
Thanks everyone for comments on our earlier thread [1] about callable type
syntax. We now have a draft PEP [2] proposing an arrow-based syntax for
callable types, for example:
```
(int, str) -> bool # equivalent to Callable[[int, str], bool]
```
In support of the PEP we also have:
- a reference implementation of the parser [3] to ensure the grammar is correct
(tests [5], [6], [7])
- a detailed specification of planned runtime behavior [4], which is not yet in
the reference implementation
We'd like to get your feedback about the PEP in general, and especially details
and edge cases we need to consider regarding runtime behavior.
Cheers,
Steven Troxler
---------
[1] Earlier python-dev thread
https://mail.python.org/archives/list/[email protected]/thread/VBHJOS3LOXGVU6I4FABM6DKHH65GGCUB/
[2] PEP 677: https://www.python.org/dev/peps/pep-0677/
[3] Reference implementation of Parser:
https://github.com/stroxler/cpython/tree/callable-type-syntax--shorthand
[4] Details on the runtime behavior:
https://docs.google.com/document/d/15nmTDA_39Lo-EULQQwdwYx_Q1IYX4dD5WPnHbFG71Lk/edit
[5] Ast tests for parser changes:
https://github.com/stroxler/cpython/blob/20eb59fdca0d6d8dbe4efa3b04038c7c22024654/Lib/test/test_ast.py#L359-L392
[6] Easy-read tests of examples from the PEP:
https://github.com/stroxler/cpython/blob/callable-type-syntax--shorthand/Lib/test/test_callable_type_examples_for_pep.py
[7] Test sanity checking hundreds of examples pulled from typeshed:
https://github.com/stroxler/cpython/blob/callable-type-syntax--shorthand/Lib/test/test_callable_type_examples_for_pep.py
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/OGACYN2X7RX2GHAUP2AKRPT6DP432VCN/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/2BKD5YBU7WJMUY3TSX34HX5IICT5UFRQ/
Code of Conduct: http://python.org/psf/codeofconduct/