On Sat, Dec 23, 2017, 09:23 William Rose, <william27.07...@gmail.com> wrote: > > I had an idea that it could be helpful to have local functions as well as > normal ones. They would be called the same way as normal ones but def would > be replaced by internal and inside they could only access variables they > have defined and inputs to them so no global variables or class variables. I > think this could be used to save people accidentally changing variables you > dont' want to change when updating your code. Let me know what you think!
You mean like this? internal myfunc(x, y, z): return sum(map(int, [x,y,z])) # SyntaxError: Undefined name 'sum'. You may want to loosen the restrictions and allow builtins. However, it is possible to redefine/create builtin names during runtime. You may also want to allow explicit declarations for global/nonlocal names, using the global and nonlocal keywords. You won't be able to access class variables, because you won't be able to access classes. This kind of function prevents a common use for functions: taking a section of an existing function and giving it a name. The proposed `internal` function type will encourage large functions that break the Rule of Three*, and require people to opt in to gain any advantages. Once they opt in, they would have to then opt out if they try to apply the Rule of Three. *https://en.wikipedia.org/wiki/Rule_of_three_%28computer_programming%29 Can you give an example of how you would use this? Could your problem perhaps be better solved with namespaces or refactoring tools? _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/