[Python-ideas] Repr of lambda

Serhiy Storchaka storchaka at gmail.com
Sun Dec 17 14:20:38 EST 2017

Currently repr of doesn't contain much of information besides that it is 
a lambda.

 >>> lambda x: x**2
<function <lambda> at 0x7f3479b74488>

All lambdas have the same repr, different only by unreadable hexadecimal 

What if include the signature and the expression of the lambda in its repr?

 >>> lambda x: x**2
<lambda x: x**2>

This would return an old feature of Python 0.9.1 

Repr of function could contain just the signature.

<function foo(bar, baz)>

But there is a problem with default values. Their reprs can be very 
long, especially in the following case with mutable default value:

def foo(x, _cache={}):
         return _cache[x]
     except KeyError:
     _cache[x] = y = expensive_calculation(x)
     return y

Maybe the placeholder should be always used instead of default values.

More information about the Python-ideas mailing list