On Sun, Dec 12, 2021 at 1:23 PM Steven D'Aprano <[email protected]> wrote:
>
> TL;DR: it is hard, but not impossible, to set function `__globals__`
> dunder to a ChainMap. Let's make it easier!
>
> Attempt 1: set __globals__ directly.
>
> >>> func.__globals__ = ns
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: readonly attribute
>
> I think we should have:
>
> - allow func.__globals__ to be writable;

CodeType has a replace() method that returns a new code object with
identical attributes but for the ones you asked to change. If making
__globals__ writable causes problems, a FunctionType.replace() method
would probably be a good alternative.

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

Reply via email to