[Python-ideas] Multi Statement Lambdas
Serhiy Storchaka
storchaka at gmail.com
Mon Oct 22 06:10:51 EDT 2018
22.10.18 02:16, Terry Reedy пише:
> All
> functions created from lambda expressions get the same pseudo-name
> '<lambda>'. This can make tracebacks worse. Perhaps more importantly,
> proper testing may become harder.
See https://bugs.python.org/issue34856. But this can work only while
lambda's body is a simple expression.
> >>> for i in map(lambda x: x **
> 2, 'abc'):
> print(i)
>
> Traceback (most recent call last):
> File "<pyshell#19>", line 2, in <module>
> 2, 'abc'):
> File "<pyshell#19>", line 2, in <lambda>
> 2, 'abc'):
> TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
In 3.8 the traceback is different (an can be even more informative with
resolved issue34856).
Traceback (most recent call last):
File "1.py", line 1, in <module>
for i in map(lambda x: x **
File "1.py", line 1, in <lambda>
for i in map(lambda x: x **
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
> Given that there might be a hundred functions named '<lambda>', I think
> the specific name is a bit helpful.
I think the main problem is not with tracebacks, but with reprs. If you
have a pack of callbacks, it is not easy to figure out what they do if
they are anonymous functions.
More information about the Python-ideas
mailing list