[Python-ideas] Repr of lambda
Ivan Pozdeev
vano at mail.mipt.ru
Mon Dec 18 01:11:03 EST 2017
On 17.12.2017 22:20, Serhiy Storchaka wrote:
> 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 address.
>
> What if include the signature and the expression of the lambda in its
> repr?
>
> >>> lambda x: x**2
> <lambda x: x**2>
>
It's the same for named functions:
In [1]: def ditto(a): return a
In [2]: ditto
Out[2]: <function __main__.ditto>
Are you intending to do the same for them?
> This would return an old feature of Python 0.9.1
> (https://twitter.com/dabeaz/status/934835068043956224).
>
> 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={}):
> try:
> return _cache[x]
> except KeyError:
> pass
> _cache[x] = y = expensive_calculation(x)
> return y
>
> Maybe the placeholder should be always used instead of default values.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
--
Regards,
Ivan
More information about the Python-ideas
mailing list