Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Representable for TypeAliasType
  • Loading branch information
youknowone committed Jul 20, 2025
commit 2c7692ba6e378678fd47e524a44266e5c1912ffe
19 changes: 10 additions & 9 deletions vm/src/stdlib/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
#[pymodule(name = "_typing")]
pub(crate) mod decl {
use crate::{
PyObjectRef, PyPayload, PyResult, VirtualMachine,
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
builtins::{PyTupleRef, PyTypeRef, pystr::AsPyStr},
function::{FuncArgs, IntoFuncArgs},
types::{Constructor, Representable},
Expand Down Expand Up @@ -88,7 +88,7 @@ pub(crate) mod decl {

impl Representable for NoDefault {
#[inline(always)]
fn repr_str(_zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
fn repr_str(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
Ok("typing.NoDefault".to_owned())
}
}
Expand All @@ -104,7 +104,7 @@ pub(crate) mod decl {
// compute_value: PyObjectRef,
// module: PyObjectRef,
}
#[pyclass(with(Constructor), flags(BASETYPE))]
#[pyclass(with(Constructor, Representable), flags(BASETYPE))]
impl TypeAliasType {
pub const fn new(name: PyObjectRef, type_params: PyTupleRef, value: PyObjectRef) -> Self {
Self {
Expand All @@ -128,12 +128,6 @@ pub(crate) mod decl {
fn __type_params__(&self) -> PyTupleRef {
self.type_params.clone()
}

#[pymethod(name = "__repr__")]
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
let name = self.name.str(vm)?;
Ok(name.as_str().to_owned())
}
}

impl Constructor for TypeAliasType {
Expand Down Expand Up @@ -176,6 +170,13 @@ pub(crate) mod decl {
}
}

impl Representable for TypeAliasType {
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
let name = zelf.name.str(vm)?;
Ok(name.as_str().to_owned())
}
}

// impl AsMapping for Generic {
// fn as_mapping() -> &'static PyMappingMethods {
// static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
Expand Down