This commit is contained in:
Shunsuke Shibayama 2022-12-14 07:38:28 +09:00
parent e67f1b9c1b
commit 3ff1675770
3 changed files with 6 additions and 13 deletions

View file

@ -1119,7 +1119,7 @@ impl Context {
generic_module.register_trait(g_module_t.clone(), generic_module_eq); generic_module.register_trait(g_module_t.clone(), generic_module_eq);
let Path = mono_q_tp("Path", instanceof(Str)); let Path = mono_q_tp("Path", instanceof(Str));
let module_t = module(Path.clone()); let module_t = module(Path.clone());
let py_module_t = py_module(Path, self.cfg.python_compatible_mode); let py_module_t = py_module(Path);
let mut module = Self::builtin_poly_class("Module", vec![PS::named_nd("Path", Str)], 2); let mut module = Self::builtin_poly_class("Module", vec![PS::named_nd("Path", Str)], 2);
module.register_superclass(g_module_t.clone(), &generic_module); module.register_superclass(g_module_t.clone(), &generic_module);
let mut py_module = let mut py_module =
@ -1849,7 +1849,7 @@ impl Context {
let t_pyimport = nd_func( let t_pyimport = nd_func(
vec![anon(tp_enum(Str, set! {Path.clone()}))], vec![anon(tp_enum(Str, set! {Path.clone()}))],
None, None,
py_module(Path, self.cfg.python_compatible_mode), py_module(Path),
) )
.quantify(); .quantify();
let t_pycompile = nd_func( let t_pycompile = nd_func(

View file

@ -65,13 +65,8 @@ pub fn module(path: TyParam) -> Type {
} }
#[inline] #[inline]
pub fn py_module(path: TyParam, py_comp_mode: bool) -> Type { pub fn py_module(path: TyParam) -> Type {
let name = if py_comp_mode { poly("PyModule", vec![path])
"ModuleType"
} else {
"PyModule"
};
poly(name, vec![path])
} }
pub fn module_from_path<P: Into<PathBuf>>(path: P) -> Type { pub fn module_from_path<P: Into<PathBuf>>(path: P) -> Type {

View file

@ -1646,9 +1646,7 @@ impl Type {
match self { match self {
Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_module(), Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_module(),
Self::Refinement(refine) => refine.t.is_module(), Self::Refinement(refine) => refine.t.is_module(),
Self::Poly { name, .. } => { Self::Poly { name, .. } => &name[..] == "PyModule" || &name[..] == "Module",
&name[..] == "PyModule" || &name[..] == "Module" || &name[..] == "ModuleType"
}
_ => false, _ => false,
} }
} }
@ -1657,7 +1655,7 @@ impl Type {
match self { match self {
Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_py_module(), Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_py_module(),
Self::Refinement(refine) => refine.t.is_py_module(), Self::Refinement(refine) => refine.t.is_py_module(),
Self::Poly { name, .. } => &name[..] == "PyModule" || &name[..] == "ModuleType", Self::Poly { name, .. } => &name[..] == "PyModule",
_ => false, _ => false,
} }
} }