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
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/T4YYAA3Q3TJRUNPAQ23TEM5XDZJ3CSML/
Code of Conduct: http://python.org/psf/codeofconduct/