![](https://secure.gravatar.com/avatar/5615a372d9866f203a22b2c437527bbb.jpg?s=120&d=mm&r=g)
On Sun, Oct 31, 2021 at 03:43:25PM +1100, Chris Angelico wrote:
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.
>>> def func(arg="finest green eggs and ham"): ... pass ... >>> inspect.signature(func) <Signature (arg='finest green eggs and ham')> >>> >>> func.__defaults__ = ("yucky crap",) >>> inspect.signature(func) <Signature (arg='yucky crap')> If help, or some other tool is caching the function signature, perhaps it shouldn't :-)
But if you want to shoot yourself in the foot, there are already plenty of gorgeous guns available.
Indeed. Beyond avoiding segmentation faults, I don't think we need to care about people who mess about with the public attributes of functions. You can touch, you can even change them, but keeping the function working is no longer our responsibility at that point. If you change the defaults, you shouldn't get a seg fault when you call the function, but you might get an exception. -- Steve