[issue34856] Make the repr of lambda contain signature and body expression.

Terry J. Reedy report at bugs.python.org
Mon Oct 22 15:26:54 EDT 2018


Terry J. Reedy <tjreedy at udel.edu> added the comment:

My understanding of the current code is that in the example above, f.__name__ would be "<lambda x, y=1: x + y>".

1. I believe this would make the representation
 <<lambda x, y=1: x + y> at 0x........>
unless functions gain a custom __repr__ method that strips the brackets off the name when present.  I don't really like the alternative of leaving the brackets off the name.

2. My proposal is to limit the length of the .__name__ attribute.  This not only limits the repr but also the function name part of traceback lines.  I consider the latter more important as I personally see function names in tracebacks far more often than in representations. Long function names wrapped to several lines would in my opinion negatively affect tracebacks.  Large collections do not affect tracebacks.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34856>
_______________________________________


More information about the Python-bugs-list mailing list