On Thu, Feb 18, 2021 at 8:46 PM Steven D'Aprano <st...@pearwood.info> wrote:
> Although I have heard from Ruby enthusiasts that the ability to write > large, complex, multi-statement anonymous block functions is really > useful, its not something I can personally say I have missed. > I think that once you get past a fairly simple one-line expression, > anything else ought to be tested; and that requires making it a named > function at the top level so that doctest or unittest can see it. > I think I can kinda sympathize with that perspective. Just like you sometimes have an elif block where "a bunch of stuff happens", sometimes you have a callback function that is only used by one other function. It cannot be a block in current Python because it's a callback, but it doesn't *really* have a meaningful name outside that of the enclosing function. On other hand, writing an inner function and using the throwaway name `fn` for it requires two extra characters. OK, maybe 4 characters since it is both defined and then used. Of course, exact character count depends on the hypothetical syntax of a "multi-statement lambda" ... but it amounts to "no big deal" in existing Python, in any case.
_______________________________________________ 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/I6DZPPDI6KPAOS573VWNLUZE6TP7LUTP/ Code of Conduct: http://python.org/psf/codeofconduct/