On Wed, Dec 2, 2020 at 10:45 AM Steven D'Aprano firstname.lastname@example.org wrote:
Is monkey-patching disallowed because `mod.func1` is defined as a constant? Or are all functions automatically considered to be constants?
If the later, then decorators won't work in strict mode:
@decorate def func(): ...
is defined as:
# define-decorate-replace def func(): ... func = decorate(func)
so if functions are automatically const, decorators won't work.
Occasionally I find that decorator syntax is not sufficient, and I've used the explicit "define-decorate-replace" form. That won't work either.
Even though decorator syntax is described as being equivalent to define-decorate-replace, it actually assigns only once. So if the definition of "constant" is "may only be bound once", a decorated function would be fine. (But doing it explicitly wouldn't.)