On 2021-02-18 at 18:10:16 +0400, Abdulla Al Kathiri <alkathiri.abdu...@gmail.com> wrote:
> I will be very happy if those versions of Callable and anonymous > functions exist in Python right now. See how elegant that would look > like.. > > def func(x: int, y: int, f: (int, int) -> int) -> int: > return f(x, y) Elegant? I realize that this is a contrived scenario, but even if the identifiers x, y, and f were meaningful (e.g., account_balance, socket_descriptor), the signal to noise ratio in that definition makes me cringe. And it only gets worse once I'm not dealing with ints. > print(func(3, 4, (x, y) => x + y)) #Out: 7 > > Imagine your mouse is on :func: ‘func’ in VSC or PyCharm and see that > you need the third parameter to be of type (int, int) -> int, you can > immediately write an anonymous function that mirrors the structure of > the annotation but instead of ->, you have =>. Straight forward. If my IDE is that clever, then it can also type "lambda x, y: " for me in addition to showing me that signature. Aside: And then a thousand developers/engineers/maintainers, auditors, and testers (not to mention future me) have to read that anonymous function. Over and over. And over. Unless it's trivial, or simpler, use a def statement, give it a name and a doc string, test it, and reuse it. And if it's that trivial, then trading "lambda" for "->" (or "=>") doesn't matter. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4QNOE7AFAAYWZWQQJ24GCUMFVX2JBI4F/ Code of Conduct: http://python.org/psf/codeofconduct/