
On Sun, Oct 31, 2021 at 06:22:09PM +1100, Steven D'Aprano wrote: [snip]
Benefits:
If I have understood Chris correctly, there's another benefit. Replacing the late bound defaults in the function object will no longer be a misleading no-op that confuses introspection tools such as inspect.signature and help(). There's no longer any need to synchronise the late defaults buried inside the code object of the function with the signatures. There is a single point of truth: - want to know the (saved) source code of the late-bound default expression? check the expression's code object in func.__defaults_extra__ - want to actually evaluate the expression? use the code object in func.__defaults_extra__ - want the signature of the function? the inspect module will know to look at the individual late-bound expression code objects in func.__defaults__extra__, rather than a cached version which may be misleading and inaccurate. -- Steve