mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-12 00:57:13 +08:00
fix import multi
This commit is contained in:
parent
7baf64e67c
commit
6d45b633d8
@ -2547,6 +2547,8 @@ static Error* compile_normal_import(Compiler* self, c11_sbuf* buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c11_string* path = c11_sbuf__submit(buf);
|
c11_string* path = c11_sbuf__submit(buf);
|
||||||
|
c11_sbuf__ctor(buf);
|
||||||
|
|
||||||
int path_index = Ctx__add_const_string(ctx(), c11_string__sv(path));
|
int path_index = Ctx__add_const_string(ctx(), c11_string__sv(path));
|
||||||
c11_string__delete(path);
|
c11_string__delete(path);
|
||||||
|
|
||||||
|
|||||||
@ -56,8 +56,19 @@ static void py_ModuleInfo__dtor(py_ModuleInfo* mi) {
|
|||||||
c11_string__delete(mi->path);
|
c11_string__delete(mi->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool module__repr__(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(1);
|
||||||
|
py_ModuleInfo* self = py_touserdata(argv);
|
||||||
|
c11_sbuf buf;
|
||||||
|
c11_sbuf__ctor(&buf);
|
||||||
|
pk_sprintf(&buf, "<module '%s'>", self->path->data);
|
||||||
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
py_Type pk_module__register() {
|
py_Type pk_module__register() {
|
||||||
py_Type type = pk_newtype("module", tp_object, NULL, (py_Dtor)py_ModuleInfo__dtor, false, true);
|
py_Type type = pk_newtype("module", tp_object, NULL, (py_Dtor)py_ModuleInfo__dtor, false, true);
|
||||||
|
py_bindmagic(type, __repr__, module__repr__);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
tests/302_import_multi.py
Normal file
4
tests/302_import_multi.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import os, math
|
||||||
|
|
||||||
|
assert repr(os) == "<module 'os'>"
|
||||||
|
assert repr(math) == "<module 'math'>"
|
||||||
Loading…
x
Reference in New Issue
Block a user