On 2021-05-27 17:44, Shreyan Avigyan wrote:
My proposal is somewhat the sum of all of your ideas. Well I propose there 
should a STORE_STATIC_FAST opcode that stores a static variable. Static 
variable will be declared only once and will be initialized to None (statement 
syntax will be similar to that of global). It will be initialized in 
MAKE_FUNCTION. Now it will be set by STORE_STATIC_FAST. Where will the 
variables be stored? It will have references in locals and __statics__. 
Therefore LOAD_FAST can find it. So I don't hope there will be performance 
decrease but performance increase is also not guaranteed. :-)

And if these are thread unsafe then is __defaults__ also thread unsafe?

Why initialise them to None? Other variables don't behave like that.

My preference would be to have something like this:

    def foo():
        static x = 0

that would bind 'x' the first time it met that statement, and if it tried to use 'x' before that has met that statement for the same time it would raise something like UnboundLocalError (perhaps UnboundStaticError in this case?) like happens currently for local variables.
_______________________________________________
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/TFTYZVYNRRX5FS2PFXRGEL6RTMCCRCRH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to