On Sun, Oct 31, 2021 at 3:31 PM Steven D'Aprano <st...@pearwood.info> wrote: > >>> inspect.signature(bisect.bisect_left) > <Signature (a, x, lo=0, hi=None, *, key=None)> > > I challenge anyone to honestly say that if that signature read: > > <Signature (a, x, lo=0, hi=len(a), *, key=None)> > > they would not be able to infer the meaning, or that Python would be a > worse language if the interpreter managed the evaluation of that default > so you didn't have to.
There is a downside: it is possible to flat-out lie to the interpreter, by mutating bisect_left.__defaults__, so that help() will give a completely false signature. But if you want to shoot yourself in the foot, there are already plenty of gorgeous guns available. Behold, the G3SG1 "High Seas" of footguns: >>> def spam(x, y, z="foo", *, count=4): ... ... >>> def ham(a, *, n): ... ... >>> spam.__wrapped__ = ham >>> inspect.signature(spam) <Signature (a, *, n)> Ahhhhh whoops. We just managed to lie to ourselves. Good job, us. ChrisA _______________________________________________ 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/44AYKJUNNODIYB576TRIW4NF7IHQPSZA/ Code of Conduct: http://python.org/psf/codeofconduct/