Hello, I see that code listing was partially garbled (code merged into some comments). It shouldn't be too bad to disambiguate it, but let me try to repost the code again:
``` import mod # Leads to a warning: replacing (monkey-patching) a constant slot (function) with a variable. mod.func1 = 1 # Leads to a warning: replacing (monkey-patching) a constant slot (function). mod.func2 = lambda: None # Way to define a constant. my_cnst: const = 1 # Leads to a warning: replacing (monkey-patching) a constant slot. my_cnst: const = 2 glb1 = 100 def fun(): # Imports are not allowed at run-time import mod2 # But you can re-import module previously imported at import-time. import mod # RuntimeError my_cnst = 3 # RuntimeError mod.func2 = lambda x: 1 global glb1, new # RuntimeError: Cannot create new global nameslots at runtime. new = 1 # Nor can delete existing del glb1 # Cheats don't work globals()["new"] = 1 # Leads to a warning: replacing (monkey-patching) a constant slot (function). def fun(): pass # fun_var is a variable storing a reference to a function (can store ref # to another func). fun_var = fun # fun2 is an alias of fun fun2: const = fun # Run-time execution starts with this function. This clearly delineates # import-time from run-time: a module top-level code is executed at # import-time (including import statements, which execute top-level code # of other modules recursively). When that is complete, strict mode # interpreter switches to run-time mode (restrictions enabled) and # executes __main__(). def __main__(): fun() # This statement is not executed when program runs in strict mode. # It is executed when it is run in normal mode, and allow to have # the same startup sequence (execution of __main__()) for both cases. if __name__ == "__main__": __main__() ``` On Tue, 1 Dec 2020 18:26:48 +0300 Paul Sokolovsky <pmis...@gmail.com> wrote: > Hello, > > Recently, there was a discussion of language-level (vs just > stdlib-level, like currently done by "typing" module) "const" > annotation. The discussion mentioned that the initial [] -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ 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/LRABLTXTAIA6MF3SKBCAP2NM2P5B72W4/ Code of Conduct: http://python.org/psf/codeofconduct/