On Wed, Dec 2, 2020 at 10:45 AM Steven D'Aprano <st...@pearwood.info> 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.)

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/PSQVUILAIASACZQSPZZXZMSWPEHR56VW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to