Any thoughts about handy syntax for coroutine functions? On Fri, 2021-06-11 at 07:20 -0700, Guido van Rossum wrote:
The shortcut (float) -> float for C1 makes sense to me, because the other interpretation would be equivalent to (float: Any) -> float, which isn’t very useful.
From a readability point of view I think making the parentheses mandatory is desirable.
I do think we need to seriously consider how a similar notation could also be used as an alternative for lambda (JavaScript has this, as does Scala IIRC).
On Fri, Jun 11, 2021 at 03:45 Sebastian Rittau
wrote: Am 11.06.21 um 01:03 schrieb Eric Traut:
Examples: ```python C1 = (x: float, /) -> float # Equivalent to Callable[[float], float] C2 = (x: float) -> float # Not expressible with Callable C3 = (*, x: float) -> float # Not expressible with Callable C4 = (v: int, /, x: float) -> float # Not expressible with Callable C5 = (x: int, *args: str, **kwargs: str) -> int # Not expressible with Callable C6 = (*args: Any, **kwargs: Any) -> None # Equivalent to Callable[..., None] ```
I really like that these look exactly like function declaration minus "def" and the name. The question is whether to even allow something like "(float) -> float" as a "shortcut" for C1 above as suggested originally by Steven. The advantage is that it's a bit more concise for the common callback case, where names don't matter, the disadvantage is that it's inconsistent with existing Python syntax.
If we go for the shortcut syntax we should always require parentheses around the arguments for readability and disambiguation.
- Sebastian
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: guido@python.org
Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: pbryan@anode.ca