Refactoring, Stdlib, everything!

This commit is contained in:
Xander Mckay 2024-10-09 15:37:26 -04:00
parent 90cc4ff466
commit b9801cad59
9 changed files with 1901 additions and 85 deletions

16
test1.py Normal file
View file

@ -0,0 +1,16 @@
import sys, types
def add_fakeimport(name: str, code: str):
module = types.ModuleType(name)
parent = '.'.join(name.split('.')[:-1]) if '.'.join(name.split('.')[:-1]) else name
if not parent == name and parent not in sys.modules:
sys.modules[parent] = types.ModuleType(parent)
globals = {'__package__': parent}
print(globals)
module.__dict__.update(globals)
exec(code, module.__dict__)
sys.modules[name] = module
add_fakeimport('abcxyzaa.b', 'print("hi"); a = lambda: print("hi")')
add_fakeimport('abcxyzaa', 'from . import b; print("hi"); a = lambda: print("hi")')
import abcxyzaa as aa
aa.b.a()