Suggestion: add the ability to modify builtin modules (conforming to the standard C-Python implementation)
Description
The standard C-Python allows modification of built-in modules. With that capability, we can create genuine global variables across all imported modules in the following way:
import os
os.g_abc = "Hello world"
Using this technique, inside any imported module, you can access os.g_abc after importing os module.
However, this is not allowed in Micropython, giving the following error:
AttributeError: 'module' object has no attribute 'g_abc'
FYI, this is the only way to create genuine global variables if your level of python profession believes that globals() can solve the problem. No. That is because globals() is only global w.r.t. the module that it is located in, not w.r.t. the global runtime. For example,
### moduleA.py
def test():
globals()['g_abc'] = 'hello'
def mainA():
print(g_abc)
### moduleB.py
import moduleA
moduleA.test()
moduleA.mainA() # this works fine
print(globals()['g_abc']). # this will crash, because the global variable is only defined within moduleA context, not in moduleB or elsewhere
Code Size
No response
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
Python module support is not yet implemented
Not trying to cause any hassle, but instead to have fact recorded, and possible to get some comments regarding planning and issues related to implementation.
So, "import" statement (well, import() builtin func) is currently not implemented (just dumps its args), and mp_module_new() has following comment:
// temporary way of making C modules
// hack: use class to mimic a module
I understand that full-fledged modules support is probably not top-priority for MCU port - being able to create C modules and using just single main Python app already allows to do a lot of things. But sooner or later it will be needed - that's what we all expect from Python - being easily to reuse 3rd-party modules, right? (Actually #7 already touched on that.) And "unix" port is pretty orphaned without it.
So, any planning/ETA when this might be implemented? Any blockers on the road? For example, I don't know if all needed things on core side are there, but I may imagine there're many "boring" questions like modules search paths, then differences between search paths/mehods for ports (MCU vs unix), support for precompiled bytecode files, etc. etc.