typevar as module (#6834)

This commit is contained in:
Jeong, YunWon
2026-01-22 22:06:14 +09:00
committed by GitHub
parent 40a43f3210
commit 8cbaf3c2ef
2 changed files with 1040 additions and 1054 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -13,12 +13,11 @@ pub fn init(ctx: &Context) {
NoDefault::extend_class(ctx, ctx.types.typing_no_default_type);
}
#[pymodule(name = "_typing")]
#[pymodule(name = "_typing", with(super::typevar::typevar))]
pub(crate) mod decl {
use crate::{
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
builtins::{PyStrRef, PyTupleRef, PyType, PyTypeRef, pystr::AsPyStr, type_},
class::PyClassImpl,
function::{FuncArgs, IntoFuncArgs},
protocol::PyNumberMethods,
types::{AsNumber, Constructor, Representable},
@@ -176,41 +175,14 @@ pub(crate) mod decl {
}
}
// impl AsMapping for Generic {
// fn as_mapping() -> &'static PyMappingMethods {
// static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
// subscript: atomic_func!(|mapping, needle, vm| {
// call_typing_func_object(vm, "_GenericAlias", (mapping.obj, needle))
// }),
// ..PyMappingMethods::NOT_IMPLEMENTED
// });
// &AS_MAPPING
// }
// }
pub(crate) fn module_exec(
vm: &VirtualMachine,
module: &Py<crate::builtins::PyModule>,
) -> PyResult<()> {
__module_exec(vm, module);
use super::{Generic, ParamSpec, ParamSpecArgs, ParamSpecKwargs, TypeVar, TypeVarTuple};
TypeVar::make_class(&vm.ctx);
ParamSpec::make_class(&vm.ctx);
TypeVarTuple::make_class(&vm.ctx);
ParamSpecArgs::make_class(&vm.ctx);
ParamSpecKwargs::make_class(&vm.ctx);
Generic::make_class(&vm.ctx);
extend_module!(vm, module, {
"NoDefault" => vm.ctx.typing_no_default.clone(),
"TypeVar" => TypeVar::class(&vm.ctx).to_owned(),
"ParamSpec" => ParamSpec::class(&vm.ctx).to_owned(),
"TypeVarTuple" => TypeVarTuple::class(&vm.ctx).to_owned(),
"ParamSpecArgs" => ParamSpecArgs::class(&vm.ctx).to_owned(),
"ParamSpecKwargs" => ParamSpecKwargs::class(&vm.ctx).to_owned(),
"Generic" => Generic::class(&vm.ctx).to_owned(),
"Union" => vm.ctx.types.union_type.to_owned(),
});