Refactoring, Stdlib, everything!
This commit is contained in:
parent
90cc4ff466
commit
b9801cad59
9 changed files with 1901 additions and 85 deletions
16
test1.py
Normal file
16
test1.py
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue